I do have a project for daily monitoring, and I have a problem getting the text from my textbox wherein my textbox is in my usercontrol.
the scenario would be, if I click the show button, the userControl.vb would be called in my panel and I dont have a problem putting up userControl.vb to my panel, if I click save button which will check if all fields are fill-up before saving the data. I would save as normal and wont check my panel where I load up my userControl.vb
this my snippet project tree:
DXApplication
|_My Porject
|_User Control <folder>
|_userControl.vb <user control form>
|_frmMainActivity <winForm>
here is my code for loading the userControl in my Panel
Friend ctrlUser As UserControl
ctrlUser = New userControlx
ctrlUser.Dock = DockStyle.Top
pnlActivity.Controls.Clear()
pnlActivity.Controls.Add(ctrlUser)
here is code for calling the textbox from userControl from another sub to check if the code can get the text.
*edited the userControl should be userControlx*
Dim uc As New userControlx
Msgbox(uc.txtLatitude.text)
when i hit the trigger button to show what text i put on my textbox i would return msgbox with empty string.
Any suggestion? where did I go wrong on calling the value of the textbox?
I've tried using:
Dim uc As New userControlx
uc.txtLongitude.text = "Test Text"
msgbox(ux.txtLongitude.txt)
It will return the Test Text, But in my UI the textbox that is loaded is empty.
in the trigger button you create a new instance of userControl, thats why the content of your textbox is emtpy
instead use
Msgbox(ctrlUser.txtLatitude.text)
Related
First, I apologize for my english, I'm still learning
I have a project in visual basic .net
It has two forms. One is the main and the other are called "details". "Details" must appears when click a label on the main form. When I close "details" form, I need to clear or reset (___.text = "") all the labels inside it. I tryed programming a close button or even in the FormClosing Event but it doesn't work.
The main form has a "New" button that cleans every label and textbox inside it. So I tryed to clear the labels of "Details" form from this button (Form2.Label1.Text = ""). But it doesn't work.
If I click "New" and then I click "Details" to open Details form, the labels had the old values. I need it clean.
Thanks
Display your "Details" Form with ShowDialog() instead of Show(), then call the PerformClick() method of your "New" Button:
' ... from within the "Main" Form ...
Dim details As New frmDetails
details.ShowDialog() ' <-- code STOPS here until "details" is dismissed
btnNew.PerformClick() ' now click the "New" button
I'm using the following code:
Dim Reply As DialogResult = MessageBox.Show("GOT IT!")
If Reply = DialogResult.OK Then '...`
When I click the Close button (red "X" in corner) the condition looking for DialogResult.OK still evaluates to true and when I check the Reply variable's value at runtime after clicking the close button it is 1 {OK}.
From the documentation on MessageBox Class it says:
Displays a message window, also known as a dialog box, which
presents a message to the user. It is a modal window, blocking other
actions in the application until the user closes it. A MessageBox can
contain text, buttons, and symbols that inform and instruct the user.
While I find the documentation on DialogBoxes a little convoluted and confusing, it appears to me (and i could be bery wrong) that the Close button should by default set the return to IDCancel which, I must assume is somehow parsed by the MessageBox class into DialogReturn.Cancel.
So why does MessageBox not show the return form the close button as DialogResult.Cancel??
This is all very confusing to me because it seems the MessageBox class is not consistent with other forms from within the same Systems.Windows.Forms namespace.
For instance, if we look at the documentation from the Form Class's .DialogResult method, it specifically tells us the return from the close button is DialogResult.Cancel:
When a form is displayed as a modal dialog box, clicking the Close
button (the button with an X in the top-right corner of the form)
causes the form to be hidden and the DialogResult property to be set
to DialogResult.Cancel.
As already stated in the comments above, you could get IDCancel result when clicking the Close Red Button, only if you add a MessageBoxButtons enum that include the Cancel option For example MessageBoxButtons.OKCancel and others.
The MessageBox.Show method is indeed a wrapper around the WinApi MessageBox function. You could see this wrapping looking at the reference sources
The behavior of MessageBox.Show is different from the link that you have pointed. That one is relative to the WinForm engine and of course the behavior of the WinForm Form class is totally managed by the library to handle the scenarios presumed for a WinForm class.
In the WinApi documentation you could find a subtle reference in the section about the Return value where they talks about the behavior when the cancel button is present. Then trial and error confirms this assumption.
You need to pass in MessageBoxButtons as an override that includes a cancel button so like MessageBoxButtons.OKCancel.
Dim message As String = "GOT IT!"
Dim caption As String = "Fancy Caption"
Dim Reply As DialogResult = MessageBox.Show(message, caption, MessageBoxButtons.OKCancel)
If Reply = DialogResult.OK Then '...`
If you dont want the caption than skip it but you'll still need a comma, like:
MessageBox.Show("GOT IT!",,MessageBoxButtons.OKCancel)
See here for full enumeration of options for MessageBoxButtons.
I have placed a SplitContainer control onto a form. I have a custom control inside panel 1. This custom control is the container for another user-control.
There is a TreeView control inside this user-control. I am trying to load another user-control onto panel 2 upon selection of a node in the tree view. But its not getting loaded. Am i missing something?
The code for loading the control is given below:
Dim ucImportExcel1 As New ucImportExcel()
frmMain.SplitContainer1.Panel2.Controls.Add(ucImportExcel1)
ucImportExcel1.Dock = DockStyle.Fill
An addition to the above: In the same treeview selection event
For the code below it sets the form text:
me.parentform.text = "Sample Text 1"
Whereas if use this code, nothing happens:
frmmain.text = "Sample Text 2"
When referred by a Directcast, it solved the problem:
DirectCast(Me.ParentForm.Controls.Item("SplitContainer1"), System.Windows.Forms.SplitContainer).Panel2.Controls.Add(ucImportExcel1)
I have a simple vb.net form a tabpanel strip, and then a seperate form which is loaded for the tabpage.
Here is the code for the button that dynamically creates new tabs:
Dim tempTab As New TabPage
initTab(tempTab)
xt.TabPages.Add(tempTab)
xt.SelectedIndex = xt.TabCount - 1
Here is the code for the "initTab":
Dim tmpTab As New MainTab
tmpTab.Dock = DockStyle.Fill
tmpTab.Panel1.Dock = DockStyle.Fill
tab.Controls.Add(tmpTab)
tab.Text = "Untitled"
tab.Name = " "
I can easily set the focus of any tab by entering following which sets the focus for example to the last tab:
xt.SelectedIndex = xt.TabCount - 1
Now the issue is, how can I set the focus to a textbox on the custom form (in my example labeled "MainTab")? I've tried virtually everything I can google and I can't seem to find any example of how to setfocus or even set/get anything from the MainTab form.
Anyone can help me?
Erm, turning a form into a child control takes some surgery. You have to set its TopLevel property to false, hide the border, make it visible. I don't see it in the code snippet, is MainTab actually a form?
Anyhoo, you cannot use the Focus() method on a control until it is visible. Odds are good that it isn't visible yet in your code snippet. Use the Select() method instead. Say:
tmpTab.TextBox1.Select()
Or just set the TabIndex property of the first control that should get the focus to 0 in the designer.
xt.Controls(xt.SelectedIndex).Controls("TEXTBOXNAME").Focus()
Just make sure that you set the Name property of the textbox you want to have focus (in this case the name would be TEXTBOXNAME) if you do it like this.
I dynamically create buttons on a form and use the button text as ids so that I can pass that to an SQL query to pull saved data about that button when necessary, but I also use an image over buttons that have information saved about them. What I need to know is how do I keep the text on the button from appearing when there is an image assigned to that button? By default vb.net shows both the text and the image and no TextImageRelation values allow for the image to take precedence. I tried changing the text color to transparent, but the outline of the text is still visible through the image. Is there anyway to keep the text value as it is but just show the image on the button?
Don't use the .Text property of the button to store your information. Use the .Tag property for your IDs. Just set the .Text property to "" (empty string), that way it won't interfere with your image.
not sure, but why not just set the value to a variable to be passed to the SQL on the button click event and not place the text on the button? If you are using the same button click event for several buttons you could check the sender's ID and then set the variable based on that.
To Enable "Button1" Click (Visible)
Button1.Enable = True
To Disable "Button1" Click (Visible)
Button1.Enable = False
Hide "Button"
Button1.Visible = True
or
Button1.Show()
Show "Button"
Button1.Visible = False
or
Button1.Hide()
You can Also Used the code to any Tools (TextBox, Label, ComboBox, Radio Button, Button, Link, GroupBox)