I want to implement simple toggle functionality on a ToolStripButton.
View Mode --> Edit Mode
Edit Mode --> View Mode
This piece of code is working fine except that ToolTip doesn't refresh. I tried AutoToolTip property. I also tried setting ToolTipText to string.Empty. But my toolstrip continues to show old tooltip text. ToolTipText should also change when I toggle.
private void btnTrackingMode_Click(object sender, EventArgs e)
{
if (_currentSheetTrackingMode == SheetTrackingMode.ViewMode)
{
_currentTrackingMode = TrackingMode.EditMode;
btnTrackingMode.AutoToolTip = true;
btnTrackingMode.ToolTipText = string.Empty;
btnTrackingMode.ToolTipText = "You are currently in Edit Mode. Click here to enter into View Mode";
btnTrackingMode.Image = ((System.Drawing.Image) ((Image) new ComponentResourceManager(typeof(MyForm)).GetObject("btnTrackingEditMode.Image")));
btnTrackingMode.ImageTransparentColor = System.Drawing.Color.Magenta;
}
else
{
_currentTrackingMode = TrackingMode.ViewMode;
btnTrackingMode.AutoToolTip = true;
btnTrackingMode.ToolTipText = string.Empty;
btnTrackingMode.ToolTipText = "You are currently in View Mode. Click here to enter into Edit Mode";
btnTrackingMode.Image = ((System.Drawing.Image) ((Image) new ComponentResourceManager(typeof(MyForm)).GetObject("btnTrackingViewMode.Image")));
btnTrackingMode.ImageTransparentColor = System.Drawing.Color.Magenta;
}
}
You can try to refresh the button's parent ToolStrip
btnTrackingMode.ToolTipText = "something";
//put your toolstrip's name here
buttonsToolStrip.Refresh();
You should be able to access the parent tool strip through btnTrackingMode.Owner if it's not directly available for some reason.
Related
I have a first order menu item that is a chevron for toggling the state of a title panel. The menu item has ToolTipText that I want to change while the tool tip window is still open (i.e. hover active).
Is there a way to make this happen ?
Code
topMenuStrip.ShowItemToolTips = true;
chevronMenuItem.ToolTipText = "Hide title";
chevronMenuItem.Click += new System.EventHandler(titleToggle_Click);
private void titleToggle_Click(object sender, EventArgs e)
{
var mi = (ToolStripMenuItem)sender;
if (titlePanel.Visible)
{
titlePanel.Visible = false;
mi.ToolTipText = "Show title bar"; // does not change while hover active
mi.Image = Properties.Resources.chevron_expand;
}
else
{
titlePanel.Visible = true;
mi.ToolTipText = "Hide title bar"; // does not change while hover active
mi.Image = Properties.Resources.chevron_collapse;
}
}
Pictures
Third image is after the tooltip is rerendered after new hover (mouse leave chevron mouse enter chevron)
According to Microsoft documentation, you must set the property AutoToolTip = false and the property ShowItemToolTips = true.
ToolStripItem uses the Text property as the default source for the
ToolTip content. Set AutoToolTip to false to use ToolTipText as the
source for ToolTip content.
To use this property, you must also set ShowItemToolTips to true.
Source: ToolStripItem.AutoToolTip Property
I have a user control that uses a textbox and a list box. List box isn't visible, it only becomes visible when user starts typing or click in text box.
I have added the user control to a group box which is on the form.
Now when the listox becomes visible, it stays inside the group box, and can't see the full height. I wan't it float on top so that i can see the full height.
I have looked around, implemented some solutions but nothing worked for me.
Constructor for the user control
namespace YarCustomControl
{
public partial class YarCustom : TextBox
{
public YarCustom()
{
InitializeComponent();
_code = "";
_id = -1;
//list box handling
listBox = new ListBox();
listBox.Visible = false;
listBox.Font = this.Font;
listBox.Location = this.Location;
listBox.BorderStyle = BorderStyle.Fixed3D;
listBox.Resize += new EventHandler(listBox_Resize);
//listBox.SelectedValueChanged += new EventHandler(listBox_SelectedValueChanged);
listBox.KeyDown += new KeyEventHandler(listBox_KeyDown);
listBox.Click += new EventHandler(listBox_Click);
//test => no affect on listbox
this.Controls.Add(listBox);
listBox.Visible = false;
}
}
}
and the following method makes the listbox visible. Both SetchildIndex (commented and not commented) throw an error
private void makeListBoxVisible()
{
Form parentForm = (this.FindForm() as Form);
//parentForm.Controls.SetChildIndex(listBox, 0);
this.Controls.SetChildIndex(listBox, 0);
listBox.Visible = true;
listBox.BringToFront();
}
What is the best approach for handling something like this?
My environment is VS2010 and WinForms.
Now when the listox becomes visible, it stays inside the group box,
and can't see the full height. I wan't it float on top so that i can
see the full height.
Simply put it directly on the Form.
I have a button on appBar. When user clicks it, it should change the icon. It will either show the Map or List so it needs to toggle between those 2.
If I use the code below with icons Symbol.Play & Symbol.Stop it toggles perfectly.
But when I use Symbol.Map & Symbol.List it does not toggle properly. (On simulator at least.) It changes sometimes, but mostly stays the same icon.
Code:
private void MapToggle_Click(object sender, RoutedEventArgs e)
{
if (JobMap.Visibility != Visibility.Visible)
{
MapToggle.Icon = new SymbolIcon(Symbol.List);
MapToggle.Label = "List";
JobMap.Visibility = Visibility.Visible;
}
else
{
MapToggle.Icon = new SymbolIcon(Symbol.Map);
MapToggle.Label = "Map";
JobMap.Visibility = Visibility.Collapsed;
}
}
Binded to XAML
AppBarButton Name="MapToggle" Icon="Map" Click="MapToggle_Click" Label="Map"
I have to make a table with possible filters in C#.
So I want to show the filters in another form using a button which switches between "Show filters >" and "< Hide filters" in the main form.
I open the filters form side by side the main form by using this code:
var frmFilters = new FrmFilterSearch();
frmFilters.SetDesktopLocation(Location.X + Size.Width, Location.Y);
if (!Filters)
{
Filters = true;
btn_show_filters.Text = "< Hide filters";
frmFilters.Show();
}
else
{
Filters = false;
btn_show_filters.Text = "Show filters >";
frmFilters.Hide();
}
The filters form open very well and the button is switching his text, but I can't close (hide) the filters form. If I click again on the button, it opens a new filter form.
I hope someone can help me with that.
Right now, you're creating a new instance of the Form each time the button is clicked.
You'll want to create an instance of FrmFilterSearch and set its location once, outside of the button click event, then show/hide the same Form. I'd suggest using the constructor:
FrmFilterSearch frmFilters = new FrmFilterSearch();
public YourConstructor()
{
frmFilters.SetDesktopLocation(Location.X + Size.Width, Location.Y);
}
private void FilterButton_Click(object sender, EventArgs e)
{
if (!Filters)
{
Filters = true;
btn_show_filters.Text = "< Hide filters";
frmFilters.Show();
}
else
{
Filters = false;
btn_show_filters.Text = "Show filters >";
frmFilters.Hide();
}
}
I have a list of objects that I'm adding to.
private List<Employee> employees = new List<Employee>();
I have a button on my form application to create a new employee object and add it to the list. Prior to clicking it, it displays "Add Hourly Employee". After clicking it, it changes to "Save Hourly Employee". I'm just using a boolean to determine what text to display.
private void addHrlyEmpBtn_Click(object sender, EventArgs e)
{
resetBtn.Enabled = true;
cancelBtn.Enabled = true;
if (!addHourly)
{
resetBtn.Enabled = true;
cancelBtn.Enabled = true;
textBox4.Enabled = false;
textBox4.Text = (employees.Count + 1).ToString();
textBox7.Enabled = false;
addHrlyEmpBtn.Text = "Save Hourly Employee";
}
else if (addHourly)
{
//Grab values, create new object, and add to list.
//Set addHourly to false;
}
//Other stuff
}
I'm trying to display employees.Count + 1 to textBox4, but for some reason it isn't working. No text is being displayed at all. Idealy, I'd like to have the text box disabled but still display the value. And I only want it to display when !addHourly.
Am I doing something wrong?
There's nothing wrong in principal with the code you wrote.
I would strongly suggest giving meaningful names to all of your variables. Names like textBox4 are likely to cause confusion for yourself and future maintainers of the code.
If the value is not changing as you expect, you are most likely not entering that if branch.
Set a breakpoint at
if (!addHourly)
See if addHourly has the value you expect.
Check if addHrlyEmpBtn_Click is being called at all.
if it isn't try associating the Click event with addHrlyEmpBtn_Click method from the designer
or add addHrlyEmpBtn.Click += addHrlyEmpBtn_Click; in the constructor