Tooltip positioning C# - c#

I have a picturebox that has a mousehover event to show a tooltip based on the status of a service. This seems to be working, but it kind of just pops up where the mouse is and sometimes under the mouse, in the middle of the picture, which doesn't look right. I was reading http://msdn.microsoft.com/en-us/library/windows/desktop/aa511495.aspx#infotipsgl and it suggested to have the tooltip moved off to the side. This would be great, but I can't figure out how to move it.
ToolTip on toolTip1 is blank and on the mouseHover event I have tried using
toolTip.SetToolTip(this.pictureBox1, "Message text.");
and
toolTip.Show("Message text.", pictureBox1);
Thanks

ToolTip tooltip = new ToolTip();
tooltip.Placement = PlacementMode.Right;
tooltip.PlacementRectangle = new Rect(50, 0, 0, 0);
tooltip.HorizontalOffset = 10;
tooltip.VerticalOffset = 20;
See Here for more details.

For windows forms you can use this overload of Show method. It allows you to set position offset relative to control that has tool tip.
In wpf as Ravi Patel has already pointed you to article simply us:
<ToolTip HorizontalOffset="10"
VerticalOffset="20" .../>

Related

c# Image and text on a button, centered in the button?

I have a button on a C# Windows Form form, and want to show an image and some text, side by side, and centered on the button. I tried aligning the image to the left and the text to the right, and I'm getting this (the periods are spaces):
|[IMAGE}.................Text|
But I want this:
|........[IMAGE] Text........|
My code looks like this:
btnChangeStatus.Text = "Change status to SUPPRESSED";
btnChangeStatus.TextAlign = ContentAlignment.MiddleRight;
btnChangeStatus.Image=Image.FromFile(#"J:\nomail.gif");
btnChangeStatus.ImageAlign = ContentAlignment.MiddleLeft;
I've searched here, and found lots of stuff for Java or HTML, but nothing for C#. Any ideas?
Thanks!
Set TextImageRelation to TextImageRelation.ImageBeforeText:
btnChangeStatus.TextImageRelation = TextImageRelation.ImageBeforeText;
btnChangeStatus.TextAlign = ContentAlignment.MiddleCenter;
btnChangeStatus.ImageAlign = ContentAlignment.MiddleCenter;
Specifies that the image is displayed horizontally before the text of a control.
UPDATE: You are right, though it sounds like this should do what you want, it's still a little to the left.
I tried around a little and using
btnChangeStatus.TextImageRelation = TextImageRelation.ImageBeforeText;
btnChangeStatus.TextAlign = ContentAlignment.MiddleRight; // <- right here
btnChangeStatus.ImageAlign = ContentAlignment.MiddleCenter;
leads to the desired result, but I can't tell why the button behaves like that.

C# Form text-align not working

i have created this label in design.
label TextAlign = MiddleCenter;
label AutoSize = false;
it looks fine in design but when i run it always align Left. No idea what is going on!
// load user image
picCerImage.Image = Image.FromFile(Global.avatarPath);
// load user fullname;
lbeCerFullName.Text = Global.userFullName;
this code is from FormLoad event and here is a picture when i run:
Sorry about my English!
I think this will work on that:
set the TextAlign to TopRight
set the Anchor to top and left.
OK! I found the problem with help of Martheen. Trim the string before loading it! :)
You can always look for other answers to problems like yours, like, for example, in How do I align my text in a label to the right side?.
Anyway, maybe this will work:
Adjust the label size so it's larger than the text.
Set the label Autosize property to False
Set the label TextAlign to TopRight, MiddleRight or BottomRight, depending on your choice.
I hope this works for you. Good luck!

Remove button border when entered

When I hover over buttons on my C# form I have them highlighted yellow like how Microsoft office products but I don't want it to show the button border. I've seen people mention FlatStyle or FlatAppearance but it doesn't seem to recognize those commands. I'm looking into rendering now but I'm new to C# and I'm certain there must be a simple way to do it, It's not something I want to spend a lot of time on if possible.
I must stress I've been reading through books on windows forms programming and haven't found any answers its not that I'm lazy but I often find SO a very good source with really good input.
Tried this:
this.TSVehicleButton.BorderStyle = None;
Tried this:
this.TSVehicleButton.System.Windows.Forms.BorderStyle = None;
I tried lots of things but didn't mention it as part of my question, I'm new to C# and didn't want to come across as stupid. People get a little bitchy when people put things that they tried and isn't right.
Use following on
public class CustomButton : Button
{
public CustomButton()
: base()
{
// Prevent the button from drawing its own border
FlatAppearance.BorderSize = 0;
FlatStyle = System.Windows.Forms.FlatStyle.Flat;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Draw Border using color specified in Flat Appearance
Pen pen = new Pen(FlatAppearance.BorderColor, 1);
Rectangle rectangle = new Rectangle(0, 0, Size.Width - 1, Size.Height - 1);
e.Graphics.DrawRectangle(pen, rectangle);
}
}
I might help you.
just use this.FlatStyle = FlatStyle.Flat;
Just set the following Button properties, for example at design time in the properties window:
FlatStyle=Flat
FlatAppearance.BorderSize=0
Or run the following code, for example for a button named button1:
button1.FlatStyle=True
button1.FlatAppearance.BorderSize=0
This worked perfectly for me, and it's so simple!
button.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); // transparent
button.FlatAppearance.BorderSize = 0;
Now the button has no borders, even when you enter the cursor. This worked perfectly on Visual Studio 2015.
there is a way of taking the border away from the button and its in the button properties.
First make sure you have clicked on the button so that the properties belong to the button.
on the properties pane go and find Flat Appearance and expand it by clicking on the + sign in front of it.
This will open more option for you, one of the option is border size which is set to 1, change this to 0,
Next, 3 lines below that there is a property called FlatStyle and its set to standard, this needs to be changed to Flat.
Flat
Job done!
Hope this helps

ZedGraph on resize?

How can I access the event that is triggered when a graph pane is resized?
After each resize, I want to fix the text size on the title and labels so they don't get huge when the window is maximized.
You can subscribe for ZedGraphControl's resize event:
zg1.Resize += new EventHandler(zg1_Resize);
But it's easier to achieve what you want by disabling the automatic font scaling on the GraphPane:
zg1.MasterPane[0].IsFontScaled = false;
If you have more than one GraphPane on your MasterPane, use:
foreach(GraphPane pane in zg1.MasterPane.PaneList)
pane.IsFontScaled = false;
See also:
http://zedgraph.org/wiki/index.php?title=How_does_the_font_and_chart_element_scaling_logic_work%3F
http://zedgraph.sourceforge.net/documentation/html/P_ZedGraph_PaneBase_IsFontsScaled.htm

OwnerDraw ComboBox with VisualStyles

I have a ComboBox that I have set DrawMode = DrawMode.OwnerDrawFixed. Then I handle the OnDrawItem event and everything works perfectly. However, it looks very different from a standard ComboBox because mine doesn't seem to be rendered using VisualStyles. Do I need to do something to specifically enable VisualStyle rendering for my owner drawn control? I have tried SetWindowTheme on my control, but I'm not sure what theme class to send. Any help would be much appreciated. Thanks!
The down side of owner-draw is that when you turn it on, the owner (you) has to draw everything. You are almost completely on your own.
If you want visual styles, then you have to call the VisualStyles APIs directly to do what you want. If you want to show selected, focussed, enabled/disabled states, then you have to write code to deal with them all.
This isn't a direct answer for your combo-box issues, but as an example of how to use VisualStyles, here is how I've used VisualStyles in an owner-drawn TreeView to draw the Plus/Minus icon:
// Draw Expand (plus/minus) icon if required
if (ShowPlusMinus && e.Node.Nodes.Count > 0)
{
// Use the VisualStyles renderer to use the proper OS-defined glyphs
Rectangle expandRect = new Rectangle(iconLeft-1, midY - 7, 16, 16);
VisualStyleElement element = (e.Node.IsExpanded) ? VisualStyleElement.TreeView.Glyph.Opened
: VisualStyleElement.TreeView.Glyph.Closed;
VisualStyleRenderer renderer = new VisualStyleRenderer(element);
renderer.DrawBackground(e.Graphics, expandRect);
}

Categories

Resources