|
i have a textbox, a button and a checkbox in my form.
if button click and then checkbox click , in my textbox i can draw rectangle ,this is not problem
but checkbox doubleclick , still i can draw rectangle to the textbox, how can i block this.
my code;
bool bbas=false;
bool rbutton=false;
private void button1_Click(object sender, System.EventArgs e)
{
bbas=true;
}
private void textbox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(bbas&&rbutton)
{
graphic.DrawRectangle(blackpen,e.X-25,e.Y-25,50,50);
graphic.FillRectangle(blackbrush,e.X-25,e.Y-25,50,50);
}
}
private void checkbox1_CheckedChanged(object sender, System.EventArgs e)
{
rbutton=true;
}
|
|
|
|
|
Hello...
I'm sorry, but I don't no exactly what you want. But I think I can solve the problem.
In the method :
private void checkbox1_CheckedChanged(object sender, System.EventArgs e)
{
rbutton=true;
}
you must change it to :
private void checkbox1_CheckedChanged(object sender, System.EventArgs e)
{
if(checkbox1.Checked)
{
rbutton=true;
}
else
{
rbutton=false;
}
}
or
private void checkbox1_CheckedChanged(object sender, System.EventArgs e)
{
rbutton = this.checkbox1.Checked;
}
Because double click event does not exists in checkbox. That's why, just use .Checked or not to enable or disable drawing.
|
|
|
|
|
if(checkbox1.Checked)
{
rbutton=true;
}
else
{
rbutton=false;
}
helped me , thank you guy
|
|
|
|
|
hi jackalfb!
just a code optimization...
rbutton = checkbox1.Checked;
you can also use this and will get the same result..
microsoc
|
|
|
|
|
|
You should do your drawing in the Paint event.
|
|
|
|
|
tkanks you friends
i think answers will help me.
|
|
|
|
|
How do I loop through the form elements in C#?
Regards,
ma se
(South Africa)
|
|
|
|
|
Just use :
<br />
foreach(Control control in this.Controls)<br />
{<br />
}<br />
<br />
|
|
|
|
|
In addition to stancrm answer, if you want to be able to iterate through all the child controls as well you can use a simple recursion:
private void IterateControls(Control c)
{
if (c.Controls.Count > 0)
{
foreach (Control child in c.Controls)
{
IterateControls(child);
}
}
}
.
.
.
IterateControls(this)
|
|
|
|
|
Thanks to both of you, but just another problem, how would I display the contents of the textbox? I have the ID which I did like control.ID, but now I need the value of the box. I went through the list of options, but couldn't find something like value or so.
Please help.
|
|
|
|
|
|
|
All that I need to do is to loop through the form, check if the control is a textbox, if so, print the ID of the textbox, together with the value typed in the box.
Please help.
|
|
|
|
|
You can check when you are iterating through all the contols to see if it's a textbox like this (if c is your control):
if (c is TextBox)
{
TextBox tb = (TextBox)c;
}
Now that you have casted c to a textbox you should be able to access all it's properties.
|
|
|
|
|
or as an alternative
TextBox tb = c as TextBox
if(tb != null)
{
MessageBox.Show(tb.text);
}
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
Somewhere there is something wrong with my code.
When I go a create my textbox dynamically I did it like this:
foreach (Hub h in lstHubs)
{
strHubs = strHubs + "<tr>" +
"<td width=\"15%\"><h5>" + h.HubName + "</h5></td>" +
"<td width=\"85%\">" + "<input type=\"text\" id=\"txtHub" + h.HubID + "\" size=\"7\" MaxLength=\"6\" class=\"InputText\" runat=\"server\" />%<br />" + "</td>" +
"</tr>";
}
When I do that loop of yours it does not bring back anything. So did I declare my textbox incorrectly?
Please help.
|
|
|
|
|
foreach(Control control in Controls)
{
TextBox textBox = control as TextBox;
if(textBox != null)
{
MessageBox.Show(textBox.Name + ":" + textBox.Text);
}
}
|
|
|
|
|
Thanks!!
What I am trying to is to display each hub, with a textbox next to it. There can be many many or few hubs for each hub group. I do it like this:
List<Hub> lstHubs = Hub.GetHubsByHubGroupID(Int32.Parse(cboHubGroup.SelectedValue));
foreach (Hub h in lstHubs)
{
strHubs = strHubs + "<tr>" +
"<td width=\"15%\"><h5>" + h.HubName + "</h5></td>" +
"<td width=\"85%\">" + "<input type=\"text\" id=\"txtHub" + h.HubID + "\" size=\"7\" MaxLength=\"6\" class=\"InputText\" runat=\"server\" />%<br />" + "</td>" +
"</tr>";
}
The way that I'm doing it seems like it's not adding it as a asp:Textbox control. I do not' know how to add it other wise to the table.
Please can toy help.
`
|
|
|
|
|
Thanks, this worked just fine.
Sorry for only getting back now.
|
|
|
|
|
Is there a class that provides Licensing mechanism for C# apps? Like a user must provide a product KEY (Registration Key) during installation?
If not then is there a tutorial or an article that I can look at? Thanks.
|
|
|
|
|
hi all,
in my form i display a print dialog after a messageboxbuttons.okcancel.
how will i decide if the user press 'ok' or 'cancel' on messagebox ???
is there a code to distinguish them ?
|
|
|
|
|
As you can see from the documentation, the MessageBox.Show()[^] method returns a DialogResult[^] which will tell you what button was pressed.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Yes...
You can get the return value from Show() method.
for example :
DialogResult dialogResult = MessageBox.Show("My Text", "My Title", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if(dialogResult == DialogResult.OK)
{
}
else if(dialogResult == DialogResult.Cancel)
{
}
|
|
|
|
|
Hi,
this is simple. read this example from msdn
Private Sub ValidateUserEntry2()<br />
<br />
<br />
' Checks the value of the text.<br />
<br />
If ServerName.Text.Length = 0 Then<br />
<br />
' Initializes variables to pass to the MessageBox.Show method.<br />
<br />
Dim Message As String = "You did not enter a server name. Cancel this operation?"<br />
Dim Caption As String = "No Server Name Specified"<br />
Dim Buttons As Integer = MessageBoxButtons.YesNo<br />
<br />
Dim Result As DialogResult<br />
<br />
'Displays a MessageBox using the Question icon and specifying the No button as the default.<br />
<br />
Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _<br />
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)<br />
<br />
<br />
' Gets the result of the MessageBox display.<br />
<br />
If Result = DialogResult.Yes Then<br />
<br />
' Closes the parent form.<br />
<br />
Me.Close()<br />
<br />
End If<br />
<br />
End If<br />
<br />
End Sub
Anant Y. Kulkarni
|
|
|
|