Hi, I am building a program with several textboxes, and I have a ContextMenuStrip to use with the textboxes.
Now I want to make the textbox's backgroundcolor change into an other color if the user clicks on the ToolStripMenuItem_1, but how do I make this work, because I don't know how to do this.
Grtz, Tom.

ToolStripMenuItem1.Click makes bgcolor change
Yousuf Khan
Ok, and thank you for all the explanations you gave me :p
I think I know almost everything I need to know to build my program ;)
Grtz, Tom.
Kishanb
Sorry for the late raction...
I know a datagridview is always better than 81 textboxes, but not in my case, as I am working on a Sudoku-program (if u know sudoku).
But thanks for the help, it works fine now
Grtz, Tom.
PS: No, I didn't already mark the textboxes as given by using textbox.tag, because I don't know what tag is for either
Tommmy77
Look, the problem is: I have 81(!) textboxes on my form.
If the user right-clicks on a textbox, a contextmenu appears where the user can choose to set the textbox as 'given' or as 'not given'. If the user choose to set the textbox as 'given', the textbox's bachgroundcolor should be changed, if the user choose to set the textbox as 'not given', the textbox's bachgroundcolor should be white.
Maybe this is a better explenation of my problem.
Grtz, Tom.
PS: I see you have wrote some code, but what do MouseUp and CType mean
hollander67
loool ok
most of controls have control.tag, the tagwilll be used to store text that you don't want your used to see it , you can use it as a flag, for example in your case if you mark the textbox as given by useing textbox.tag when you iterate through form controls you can just given textbox values
For Each ctrl As Control In Me.Controls
If ctrl.GetType() Is GetType(TextBox) andalso ctrl.tag = given Then
like that you will just get the given textbox to iterate through more over if you get this given flag from database you can bind your database column to the textbox.tag
hope this helps
Sid007
hi,
i guess your explanation didn't add something to the case , you can simply mark the textbox as given by useing textbox.tag or anyother way (i guess you allready did that)
81 textbox in a form is not the best solution i think you may use datagridview better than single textboxs
mouseup is event occure when you click a mouse button and release it (because the contextmenu appear when you rightclick the control so mouseup event handler to handle that event and to make it behave as you want
Ctype = cast type, when your textbox capture the event , call the method that related to this event (ie. textbox_mouseup) and send declaration about himself as sender but sender is object class not textbox class so i had to cast it back to textbox to be able to deal with its properties
hope this helps
Chunda
mmmm the problem is i don't know any connection between teh control and the contextmenu , so i think you can do it this way
Public Class Form1
'indecate which textbox was clicked Dim mytextbox As TextBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each ctrl As Control In Me.Controls
If ctrl.GetType() Is GetType(TextBox) Then 'add contextmenu to the textbox ctrl.ContextMenuStrip = Me.ContextMenuStrip1
'add event to it to Target textbox_ mouseup method AddHandler ctrl.MouseUp, AddressOf Me.TextBox_MouseUp
End If Next End Sub Private Sub TextBox_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
'change the current selected textbox mytextbox = CType(sender, TextBox)
End Sub
Private Sub BColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BColorToolStripMenuItem.Click
mytextbox.BackColor = Color.Red
mytextbox.ForeColor = Color.White
End Sub
End Class
hope this helps