I am tired of trying to deactivate the button highlight when it's activated with "istab" set to true.
Basically, I want to deactivate the back highlight of a button (if it's activated) when I click on the picture box. The method partially works. The istab deactivation works when I click on the picture box and the highlight goes away. But I made a method so that when the mouse hovers over the button, "istab" automatically reactivates. But it doesn't seem to work. The "istab" remains deactivated.
Here is what I have tried so far.
private void LogoImage_Click(object sender, EventArgs e)
{
if (btnEssentialRules.IsTab == true)
btnEssentialRules.IsTab = false;
}
private void btnEssentialRules_MouseHover(object sender, EventArgs e)
{
if (btnEssentialRules.IsTab == false)
btnEssentialRules.IsTab = true;
}
Where the btnEssentialRules is the button name.
If you have another solution or a fix to my code. please help me.
Related
I have an application which runs mostly within the taskbar, and its icon may be left clicked in order to open a Windows form.
The NotifyIcon also has a few MenuItems which can be accessed by right clicking, and each have their own click events to serve their functionality.
private void menuItem4_Click(object Sender, EventArgs e)
{
if (programEnabled == false)
{
programEnabled = true;
Console.WriteLine("Enabled!");
}
else
{
programEnabled = false;
Console.WriteLine("Disabled!");
}
}
//Icon clicked!
private void notifyIcon1_MouseClick(object Sender, EventArgs e)
{
//Reopen the form
Form f = new TemperForm();
}
Every time a MenuItem click event is activated however, NotifyIcon_Click also runs and I need that event for opening the Windows form. I don't want every time I click any MenuItem to also run the code that I wish to run when the icon is clicked.
How can I still use the NotifyIcon_Click event while not having it run every time I click a MenuItem?
I've been at this for hours and it's driving me up the wall!
To create a mouse over button I use this code
private void btnCreateAccount_MouseHover(object sender, EventArgs e)
{
btnCreateAccount.ForeColor = Color.Gold;
}
private void btnCreateAccount_MouseLeave(object sender, EventArgs e)
{
btnCreateAccount.ForeColor = Color.Black;
}
The mouse over button works however when I hover over the button there is a good at least 1 second delay. I would think that it should change colour as soon as the mouse is placed over the button and not with a (in my opinion) too long delay.
Is there any way of fixing that code by like refreshing the button or something along those lines? or perhaps someone has a code that works perfectly?
You are handling the Mouse Hover event. This will require the cursor to be still for a short while in order to fire.
The pause required for this event to be raised is specified in milliseconds by the MouseHoverTime property.
This is read only.
Normally if you want the colour to change immediately you should handle the Mouse Enter event:
private void btnCreateAccount_MouseEnter(object sender, EventArgs e)
{
btnCreateAccount.ForeColor = Color.Gold;
}
I'd like to create a roulette game, and I've made a PictureBox with an image of a roulette table.
I've tried to set Visibility = False in the property and in code:
pictureBox1.Visible = !pictureBox1.Visible;
But when I click on the hidden PictureBox, nothing happens.
Do you have any idea how to make it work?
I want to make it visible from being invisible, by clicking on it.
Once you make the visibility of an Item false, it can no longer be clicked. You can handle the click event on the form or container level, check that the mouse coordinates are contained in the bounds of the PictureBox and use that to make it visible again.
i.e.
//Common eventhandler assigned to all of your PictureBox.Click Events
private void pictureBox_Click(object sender, EventArgs e)
{
((PictureBox)sender).Visible = false;
}
private void Form1_Click(object sender, EventArgs e)
{
foreach (var item in this.Controls) // or whatever your container control is
{
if(item is PictureBox)
{
PictureBox pb = (PictureBox)item;
if (pb.Bounds.Contains(PointToClient( MousePosition)))
{
pb.Visible = true;
}
}
}
}
Problem with your logic is that once the PictureBox is made invisible, you can no longer click it anymore, since it's no longer on the form, and while you can for sure click the empty space it left, you're still not clicking it.
A possibility would be to, instead of making visible/invisible, to put/remove its background picture, so it appears to have disappeared but in fact it's still there, still able to receive clicks and respond to events.
If you want to make the pictureBox1 not visible, you would write pictureBox1.Visible = false;
Edit: What you are doing should work. I created a winform and put a picture box in it. I double clicked the picture box to make Click event handler and typed pictureBox1.Visible = !pictureBox1.Visible;. When I debug the program and click on the picture box, it turns invisible. I can't think of why it isn't working for you.
Edit: I understand what you want now. To make it visible on the click of it when it is invisible. Unfortunately I don't know how to do that.
A maybe-silly but simple way might be to put one picture box on top of the other. pictureBox1 would be your picture, pictureBox2 would have no picture. Then you could do something like this:
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Visible = false;
pictureBox2.Visible = true;
}
private void pictureBox2_Click(object sender, EventArgs e)
{
pictureBox1.Visible = true;
pictureBox2.Visible = false;
}
You could put each of your PictureBox controls in a Panel control. Then handle the Click event of both the Panel and the PictureBox.
private void panel1_Click(object sender, EventArgs e)
{
pictureBox1.Visible = true;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Visible = false;
}
I want to show the list of items in a combo box when the user selects the text. I have a touch screen application and it's very difficult to hit the dropdown arrow so I figure I'd show the menu when the text is selected which is often what gets touched. I'm using VS 2008. and suggestions for a touch friendly numeric up down solution in VS2008?
You could use the ComboBox.Click event handler and the ComboBox.DroppedDown property and do something like this:
private void ComboBox1_Click(System.Object sender, System.EventArgs e)
{
ComboBox1.DroppedDown = true;
}
You could also use the same event handler for a numericUpDown and use the mouseposition as well as the position and height of the NumericUpDown to get whether or not the click was above or below the halfway-line of the control by doing something like this (not sure if my math here is perfect, but it worked when I tested it):
if ((MousePosition.Y - this.PointToScreen(NumericUpDown1.Location).Y < NumericUpDown1.Height / 2))
{
NumericUpDown1.Value += 1;
}
else
{
NumericUpDown1.Value -= 1;
}
HTH
I was working on a similar situation. We wanted to make the text area behave the same as the button on the right. (IE the user clicks and gets the drop down box)
davidsbro is similar to what I ended up doing, but we wanted it to close if they clicked again, so the value became dropDown.DroppedDown = !dropDown.DroppedDown;.
The issue with this is that if the user clicks the right button of the drop down box, the dialog box opens, then calls the onClick event.
I solved this situation by tracking the original state via the onmouseover event. If the value has changed, we have to assume that the button on the select box handled the click already.
private bool cbDropDownState = false;
private void dropDown_MouseEnter(object sender, EventArgs e)
{
cbDropDownState = dropDown.DroppedDown;
}
private void dropDown_Click(object sender, EventArgs e)
{
if (dropDown.DroppedDown == cbDropDownState )
dropDown.DroppedDown = !dropDown.DroppedDown;
}
I am trying to make the save button visible when text is entered into the text box by using the following code:
if (tbName.TextModified == true)
{
btnCTimetablesOk.Visible = true;
}
else
{
btnCTimetablesOk.Visible = false;
}
but it gives error at tbname.textmodified
is there any other way to visible the button when we enter the text in text box
this is error i am getting "the event textbox.textmodified can only appear on the left hand side of += or -="
Try using the textbox's Enter and Leave events to show/hide your button:
private void textBox1_Enter(object sender, System.EventArgs e)
{
btnCTimetablesOk.Visible = true;
}
private void textBox1_Leave(object sender, System.EventArgs e)
{
btnCTimetablesOk.Visible = false;
}
Then modify your textbox to use these new methods.
If I'm reading your text correctly, you want the save button to be visible when the textbox has text in it and invisible when the text box is blank. If that's the case, you can use the Leave event (which occurs when the textbox loses focus) and a simple if statement:
private void textBox1_Leave(object sender, System.EventArgs e)
{
if(textBox1.Text != "")
btnCTimetablesOk.Visible = true;
else
btnCTimetablesOk.Visible = false;
}
You can also put this conditional block in any other methods kicked off by events that change the text of the box.
Also, you might want to consider using Enabled instead of Visible, it'll leave the button on the form but will gray out the text and clicking will do nothing.
I'm going to take a stab in the dark here and assume that the button is related to the textbox and you probably want someone to be able to type something in the textbox then click the button. You probably don't want the user to have to type something, then tab out or click somewhere else to make the button visible then click the button.
tbName_TextChanged(object sender, EventArgs e)
{
btnCTimetablesOk.Visible = !String.IsNullOrEmpty(tbName.Text)
}
Btw you're getting that error because TextModified isn't a boolean property, it's an event, like TextChanged or Leave or Enter. You can assign an event handler to it but you can't just check it like that.
As an aside I personally hate systems hungarian for winforms controls. I'd much rather have a timetablesOkButton than a btnCTimeablesOK button. That way if you also have a timetablesNameTextBox you can see at a glance that the button and the textbox match. Of course it may not be up to you.