C# - Add glass button on toolstrip control? - c#

How do I add a GlassButton to a ToolStrip using C#. My code is:
ToolStrip toolStripTaskBar = new ToolStrip();
GlassButton gBtn = new GlassButton();
ToolStripButton button = (ToolStripButton)gBtn;
toolStripTaskBar.Items.Add(button);
I'm getting the following exception:
Cannot convert type 'Glass.GlassButton' to 'System.Windows.Forms.ToolStripButton'
Any suggestions how can I achieve this?

Use ToolStripControlHost instead of ToolStripButton to add your custom button to the ToolStrip:
ToolStrip toolStripTaskBar = new ToolStrip();
GlassButton gBtn = new GlassButton();
ToolStripControlHost button = new ToolStripControlHost(gBtn);
toolStripTaskBar.Items.Add(button);

You're going to have to wrap your GlassButton is a class that bases ToolStripItem. The scope of issues you're going to run into with this is unknown and too broad for this forum.
The bottom line, a GlassButton is not, and does not base, ToolStripItem and that's why you're getting the error.

Related

MouseHover code for a button in c# (to display a tooltp rectangle message)

As question says, the code of my button is pretty basic:
RichTextBox1.SelectionFont = new Font("Tahoma", 12, FontStyle.Underline | RichTextBox1.SelectionFont.Style);
RichTextBox1.Focus();
All I want to do, is that when the user Hovers over this button, a little tooltip rectangle shows up "Underline"
Using WinForms with C#
I think your are using the button to underline the text in RichTextBox. What you can do is, you can add ToolTip tool in ToolBox and in Form_Load just write this code.
toolTip1.SetToolTip(button1, "Underline");
Instead of 'button1' you can give the name of your button
Have you tried smth like this?
ToolTip tip = new ToolTip();
tip.ToolTipIcon = ToolTipIcon.Warning;
tip.IsBalloon = true;
tip.Show("tooltip content", this, new Point(500, 500));
or I didn't understand your question?
Add a ToolTip control to your Form.
Now select the Button in question and set its "ToolTip on ToolTip1" property to "Underline".

Add tooltip to a dynamically created tabpage

I'm having a difficult time trying to work with tooltips.
I'm trying to add a tooltip with different text to each dynamically created tab in a tabcontrol.
It's important to note that this tab is created from a form that contains a docked form where the tabcontrol is in.
This is, a main Form with a docking area, in where I have docked a results form, which contains an - initially empty - tabcontrol.
When you start the application this results form doesnt exists, I also create it dynamically whenever the user press certains parts of the main form, each one created as a new tab in the results form tabcontrol.
This is how I generate the tabs:
generateResultForm();
TabPage newtp = new TabPage("Nuevo paciente")
_result.TabControl.TabPages.Add(newtp);
newtp.Name = setTabName("np");
Now, I've tried putting a tooltip in the results form, then tried to first generate the tooltip by adding below something like _result.ResultsTooltip.SetToolTip(newtp, "Creación de un nuevo paciente.");, which didn't work. Then, since once the tab is created, it becomes selected, I tried to add it in the results class by something like WorkareaTooltip.SetToolTip(tabControl.SelectedTab, "Cosas"); in the selectedindexchange event from the tabcontrol.
I don't think it would have been a great solution, but I don't know what else to try.
Of course the tabcontrol has its ShowToolTips property set to true.
If anyone could help me that'll be great.
Thanks for reading, and sorry if there are any language mistakes :)
//EDITED
This is the code i'm actually using (and doesn't work)
TabPage newtp = new TabPage("Nuevo paciente");
_workareaform.TabControl.TabPages.Add(newtp);
newtp.Name = "np";
var tooltip = new ToolTip();
tooltip.SetToolTip(newtp, "Creación de un nuevo paciente.");
Now, it doesn't work, might be because of the whole configuration.
Just to be clear, this tab is in a TabControl which is in a Form docked into a dockContainer in another Form.
Here is an image if it.
http://i.imgur.com/fVz6e06.png
As you can see, no tooltip at all.
Have you tried setting ToolTipText property as shown below?. It worked for me.
_result.TabControl.ShowToolTips = true;
TabPage newtp = new TabPage("Nuevo paciente");
_result.TabControl.TabPages.Add(newtp);
newtp.ToolTipText = "this is tooltip";
If you're working with another form you need to reference the other form TabControl
In this sample I create a Form1 instance (with TabControl in it) from my Form2 and then add page and tooltip.
private void Form2_Load(object sender, EventArgs e)
{
//instantiate another form
var f1 = new Form1();
//find tabcontrol on new form
var tc = (TabControl) f1.Controls["tabControl1"];
//create page
TabPage newtp = new TabPage("Nuevo paciente");
newtp.Name = "Paciente1";
tc.TabPages.Add(newtp);
//add tooltip
var tt1 = new ToolTip();
tt1.SetToolTip(newtp, "paciente 1 tooltip");
//show other form
f1.Show();
}

WP7 - ContextMenu doesn't show on Hyperlink

I'm trying to programmatically add a ContextMenu to a Hyperlink. I've searched in the documentation and in forums, and seems that the correct solution should be this:
var link = new Hyperlink();
link.Inlines.Add(new Run() { Text = linkText });
link.FontWeight = FontWeights.Bold;
link.TargetName = linkText;
link.Click += new RoutedEventHandler(link_Click);
ContextMenu menu = new ContextMenu();
MenuItem item = new MenuItem();
item.Click += new RoutedEventHandler(CopyLink);
item.Header = "copy link";
item.Tag = linkText;
menu.Items.Add(item);
ContextMenuService.SetContextMenu(link, menu);
This code compiles and does not throw any exception. I've tested and the ContextMenu is indeed added to the Hyperlink. The problem is that it will not show anytime. I can tap & hold the link all the time of the world and the menu will not appear. Also tried to add a listener with GestureService and GestureListener, but the Hold event does not fire at all.
Anyone can help me? Thanks.
You can't do ContextMenus on Hyperlinks. You can do it on a HyperlinkButton, though. I'm not exactly sure of the reason, but it does work. Depending on what you're trying to do, HyperlinkButton may have been what you wanted anyway (Hyperlink is usually only used inside documents of text).
I just found the answer while reading the Windows Phone 7.5 Unleashed book by Daniel Vaughan. My problem was that I needed to add a hyperlink in a RichTextBox, and I can only use Inlines to show text. Hyperlink is an Inline, but does not support ContextMenu. As Tim suggested, I needed to use HyperlinkButton. The solution is that there is a class called InlineUIContainer. So, this
var inline = new InlineUIContainer { Child = SomeHyperlinkButton }
made the trick for me.

IBeam caret on contextmenu of RichTextBox

I create a contextmenu and add this to a richtextbox. Now when I Right Click on the richtextbox, the contextmenu appears, but the cursors is an IBeam caret and not the default arrow.
Does anybody know how to fix this?
var tb = new RichTextBox();
tb.Text = "test";
var items = new[] {new MenuItem("Save",SaveTextFile)};
var ctxMenu = new ContextMenu(items);
tb.ContextMenu = ctxMenu;
Thanks,
Erik
I'm dreadfully sorry, but there is no way to fix this. It has been an issue with Winforms for a long time. See here and here.
Microsoft promised to look into it, but apparently they haven't fixed it yet.

Adding controls to TabItems dynamically at runtime in C#

So, here is my issue, im working in a Wpf application, so i dont have all of the standard windows form controls.. so im attempting to use a windowsformshost, to hold a webbrowser inside of a tabitem. So here is what i have:
Tab t = new Tab();
Browser newbrowse = new Browser(t);
WindowsFormsHost host = new WindowsFormsHost();
Grid g = new Grid();
host.Child = newbrowse;
newbrowse.Dock = DockStyle.Fill;
g.Children.Add(host);
t.Header = "New Tab";
t.Content = g;
tabControl1.Items.Add(t);
now, Tab, and Browser, are just my custom implementations of the controls, and they both are tested and working. So that is not the issue. Now as far as i can see, that code should work. But I'm left staring at a blank tab page. Note that this will need to be in the codebehind and cant be included in the WPF itself.
Thanks for any input! :) Cheers
EDIT: Note that i have also tried the operation with the standard, controls.tabitem, and forms.webbrowser to the same effect
I just tried this, and apparently what breaks your plan is the line:
newbrowse.Dock = DockStyle.Fill;
Comment it out, and watch how it suddenly works!

Categories