How to manually center button's caption in VB6 - vb6

I have problem with button's caption in VB6.
I'm trying to change caption after "_load" event and it works, but new text is not in the center of the button - and it's a problem.
You can see it on the following screen:
https://dl.dropboxusercontent.com/u/3779161/buttons.png
I've tried to use "Refresh" function but without any effect.
Is it possible to refresh button without creating new one?
Thanks for help

I am unable to test VB6 code currently but, apparently, it requires Win-API calls to align the text. code here. Copy the code into a Module and then you can call the function AlignCommandButtonText. (Seems like hard work!)

the new text does center for me.
run the following test project and click on the form:
'1 form with
' 1 commandbutton: name=Command1 caption="Test"
Option Explicit
Private Sub Form_Click()
Command1.Caption = "New Test"
End Sub
the problem is probably caused by something else.
for example: do you have any tight loops?
could you post some of your code?

Related

Lazarus button toggle mechanism

I wrote a little tool in Lazarus to use it as a launcher for some games of mine, all of this is done by cmd scripts which are linked to the press of a button.
Now I'm looking for two modifications to my tool, but since I'm not very talented when it comes to programming, I hope somebody can help me.
The first thing I'm looking for is to split the TButton caption into two lines. I have tried to do it over the GUI but did not find a solution for this.
The second thing I want to do is to change the caption and the function of a button by pressing on it. For example Button1 has the caption Enable Enhancements, which runs the script enhancements_on.bat. After I press the button, I want it to change the caption to Disable Enhancements, in order that the script enhancements_off.bat will run on next press.
Is this possible? if yes, how do you do it?
I've find out. In case anyone needs a feature like this, use a togglebox and the following code:
procedure TForm1.ToggleBox1Change(Sender: TObject);
begin
if ToggleBox1.Checked then
begin
ToggleBox1.Caption:='Mods aktiviert.'
ShellExecute(0,nil, PChar('cmd'),PChar('/c "start enhancements_on.bat"'),nil,1)
end
else ToggleBox1.Caption:='Mods deaktiviert.';
ShellExecute(0,nil, PChar('cmd'),PChar('/c "start enhancements_off.bat"'),nil,1)
end;
The first thing I'm looking for is to split the TButton caption into two lines.
Simply set the caption of the Togglebox at runtime, e.g. in the OnCreate event of the form and use LineEnding to split the lines.
Togglebox1.Caption := 'Line 1' + LineEnding + 'Line 2';
Note that this works only with TTogglebox, not with TButton.

How to scroll to a particular co-ordinate in Test Complete

I have spied a notepad and text box of a notepad contains a string which will be visible only if you scroll down.
Now I am trying to perform a single click there via passing a rectangle co-ordinate to the Test Complete.So with that it is able to click if it is visible on the screen otherwise it fails saying :"there was an attempt to perform an action at a point which is beyond the screen"
Is there any way where we can scroll to the point of interaction before performing the action.
I tried with following steps to achieve that but its of no help.
testObj.setFocus()
testObj.hover()
testObject.MouseWheelScroll(an integer value)
Please try this..
testObj.scrollIntoView(true);
I'm using this code and this is working fine for me..

Making picturebox preform a function when clicked VB6

I have a picturebox on my form. When I click on it, I want it to preform a function (in this case, setting a value to a variable). I, however, have not found any way to do this.
The picturebox, should during runtime, when clicked, set a value to a variable.
I have considered putting a textbox over the picturebox and making it transparent, but I have not found a way to make textboxes transparent via visual basic. There should be a more direct way available?
Can I get some help? Thanks.
You can double click on the picture box and it will bring up the code. From there insert the code you want
Private sub picture1_click()
End sub

How to get the text from the textbox added to the ListBox?

So i made a notepad type of software from Visual Baisc 6 and i am trying to add the text from my textbox to the Listbox. I tried to do many things but couldn't. I am not able to get to the correct code to do that.
I used list box "lstListBox" a text box "txtText" and a command button "cmdAdd"
Private Sub cmdAdd_Click()
lstListBox.AddItem txtText.Text
End Sub
this worked for me should work for you too, just like what OldBoyCoder commented hope this helps you understand better what he meant.

Textbox anchored to a form on all 4 sides not displayed properly

I'm running into a problem trying to anchor a textbox to a form on all 4 sides. I added a textbox to a form and set the Multiline property to True and the Anchor property to Left, Right, Up, and Down so that the textbox will expand and shrink with the form at run time. I also have a few other controls above and below the textbox.
The anchoring works correctly in Visual Studio 2005 (i.e. I can resize the form and have the controls expand and shrink as expected), but when I run the project, the bottom of the textbox is extended to the bottom of the form, behind the other controls that would normally appear beneath it. This problem occurs when the form loads, before any resizing is attempted. The anchoring of the textbox is correct for the top, left, and right sides; only the bottom is malfunctioning.
Has anybody heard of this and if so, were you able to find a solution?
Thanks!
UPDATE:
Here is some of the designer code as per Greg D's request (I am only including the stuff that had to do with the textbox itself, not the other controls):
Friend WithEvents txtRecommendationText1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.txtRecommendationText1 = New System.Windows.Forms.TextBox
' ...snip...
'txtRecommendationText1
Me.txtRecommendationText1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.txtRecommendationText1.Location = New System.Drawing.Point(4, 127)
Me.txtRecommendationText1.Multiline = True
Me.txtRecommendationText1.Name = "txtRecommendationText1"
Me.txtRecommendationText1.Size = New System.Drawing.Size(223, 149)
Me.txtRecommendationText1.TabIndex = 10
End Sub
ANOTHER UPDATE:
The textbox I originally posted about was not inherited from a baseclass form (although it was added to a custom User Control class; I probably should have mentioned that earlier), but I recently ran into the same problem on a totally unrelated set of controls that were inherited from a baseclass form. It's easy to blame these problems on possible bugs in the .NET framework, but it's really starting to look that way to me.
Is your Form localized? Check the resource files for an entry with Textbox.Size, delete is and reset the size.
Is your Form inherited and is the Textbox on the baseform? Try setting the Textbox's access modifier to Protected or Public.
Have you implemented custom resize logic? Turn it off and see if the problem is still there.
Have you entered a Textbox.MinimumSize/MaximumSize? Remove or change the value.
It might also be a combination of these things...
Does the form snap back to the expected layout when you resize it after it's been initialized weirdly? Also, have you set a Height or MinimumHeight/MaximumHeight property for the text box?
If possible, a few snippets from the designer code might be useful. :)
One possibility that I've run into in the past is DPI. If you're running/testing your code on a machine with a different DPI setting than the machine that you're developing on, you may observe some strange things.
The anchor functionality essentially establishes a fixed distance between the edge of a control and the edge of the control's parent. Is your textbox embedded within another control (e.g., a panel) that doesn't have its anchors properly set? Right clicking on the text box in the designer should pop up a menu that lets you select any controls that exist underneath it, also.
Does your program include any custom resize logic, or does it modify the size of the textbox programmatically outside of designer-generated code? That might also result in weird behavior. I've assumed maintenance for a number of pieces of software at my organization where the original developers spent a great deal of time implementing (buggy) resize logic that I had to tear out so that I could just let the designer-generated code do the work for me.
The textbox I originally posted about was not inherited from a baseclass form (although it was added to a custom User Control class; I probably should have mentioned that earlier), but I recently ran into the same problem on a totally unrelated set of controls that were inherited from a baseclass form. It's easy to blame these problems on possible bugs in the .NET framework, but it's really starting to look that way to me.
It's very likely because of the 'AutoScaleMode' property being set in InitializeComponent(). Try setting it to 'None' and see if that fixes it. I've had these problem a couple of times now.

Resources