Display tooltip only when text in Infragistics' UltraCombo is too long - winforms

We are using Infragistics' UltraCombo in a WinForms app.
Sometimes the displayed text (in the combo box itself, i.e. when it's not expanded) is too long to be completely shown.
Is there any way to only provide tooltips when this text is cut off and not to show the tooltip when the displayed text completely fits into the UltraCombo combobox?
Many thanks...

The only way I am aware is to manually determine if the current text is too wide.
Add a tooltip to the form. Then handle the TextChanging event on your combo box.
private void ultraCombo1_TextChanged( object sender, EventArgs e )
{
var textWidth = TextRenderer.MeasureText( ultraCombo1.Text, ultraCombo1.Font ).Width;
var textBoxWidth = ultraCombo1.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth;
if ( textWidth < textBoxWidth )
toolTip1.SetToolTip( ultraCombo1, "" );
else
toolTip1.SetToolTip( ultraCombo1, ultraCombo1.Text);
}

Related

WPF - Clear all textboxes in All TabItem of TabControl

In WPF, I use tabcontrol have tabitems to create new Dynamic content. I have button Reset to clear all textboxes in All TabItems. My code is working with tab focus. But, When I click the other tab and click again old tab, The content show again. Please help me so that I can clear all textboxes in all tabItems
My Code here:
private void ClearControls(DependencyObject root)
{
System.Windows.Controls.TabControl controls = new System.Windows.Controls.TabControl();
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
{
var control = VisualTreeHelper.GetChild(root, i);
if (control is System.Windows.Controls.TextBox)
{
(control as System.Windows.Controls.TextBox).Text = String.Empty;
}
else if (VisualTreeHelper.GetChildrenCount(control) > 0)
{
ClearControls(control);
}
}
}
private void BtnResetTurnbyTurn_Click(object sender, RoutedEventArgs e)
{
ClearControls(this);
}
Don't waste your time with tree visualizer
Design your ui in a separately usercontrol and give a name then from
Then head to your main window and give the area that is supposed to display the ui a name or just declare a grid and give it a name
Now head to your tabs and double click the one that is suppoused to show the ui you want and from the code just write the following
Just to clarify the names
I have my separately designd ui in a file called pages and it's name is myui and my usercontrol tag is name child
My viewing area is filled with a grid named
Mainview
I have double clicked the required tab and it drove me to the cs file inside the click event
My code is
` pages.myui mu =new pages.myui();
Mainview.Children.Clear();
Mainview.Cildren.Add(mu.child);`
It might be the most basic way to accomplish the mission but believe me it is a life saver
Comment for any question
I hope i have helped you
Yusuf naeem

windows forms application - how to make the tabs in a tab control get full width?

So i'am working with tabControl in windows forms application and i want to make the tabs get full width regardless whether the application window is maximized or not.
When the window isn't maximized everything appears great:
But when the window gets maximized the tabs doesn't get the full width:
Is there any known way to fix this problem?
Thanks in advance
You can achieve this in some way by modifying the ItemSize property as described bellow, else you'd have to draw the tab page selectors yourself.
public Form1()
{
InitializeComponent();
tabControl1.SizeMode = TabSizeMode.Fixed;
tabControl1.ItemSize = new Size((tabControl1.Width / tabControl1.TabPages.Count) - 1, tabControl1.ItemSize.Height);
}
//Hook to form or parent container Resize event, either Resize or ResizeEnd.
private void Form1_ResizeEnd(object sender, EventArgs e)
{
tabControl1.ItemSize = new Size((tabControl1.Width / tabControl1.TabPages.Count) - 1, tabControl1.ItemSize.Height);
}

How to show a panel dynamically on mouse enter event?

Like in web page using css we can show a div on mouse enter or hover, in the same way i want to show a panel on mouse enter event of a button, but i am unable to do this. I am trying like this.
private void btn2_MouseEnter(object sender, EventArgs e)
{
Button btn = (Button)sender;
btn.BackColor = System.Drawing.Color.MistyRose; //this is executed on mouse enter
Point locationOnForm = btn.FindForm().PointToClient(
btn.Parent.PointToScreen(btn.Location));
Panel pnl = new Panel();
Label lbl = new Label();
lbl.Text = "anything";
pnl.Controls.Add(lbl);
pnl.Location = new Point(locationOnForm.X, locationOnForm.Y);
pnl.Size = new Size(500, 500);
pnl.BackColor = Color.SkyBlue;
pnl.Visible = true;
pnl.Show();
}
I am not getting how to solve this. I want to know that
1) Is this the right approach or there is any other way of doing this?
2) If this is ok then what is the mistake i am doing here ?
Thanks.
Don't create the panel on mouse enter, rather have the panel created already then just show and hide it.
private void button1_MouseEnter(object sender, EventArgs e)
{
panel1.Show();
}
You have to add the panel to the Form controls
Form1.Controls.Add(pnl);
If you plan to have a panel hover over the button like a <div> in Web, you will have to call
BringToFront() to ensure that the panel does not appear behind the button or other controls on the form -
pnl.BringToFront();
Also like the previous answer, it may be better to have a panel placed on the form already and just set visible to true or false as well as the panel location otherwise you may end up adding multiple panels to the Form controls.
If you plan on just showing plain text in the panel, it may be easier to use Tooltip control -
MSDN - Tooltip Control

richtextbox binding

I have 2 RichTextBoxes (rtb1, rtb2), I something wrote in rtb1 and click on enter key, on this event is added text from rtb1 to rtb2. I solved this in code behind, it is possible this same write in XAML?
C# code:
private void rtb2_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
var textElement = new Run() { Text = rtb2.Text };
var paragraph = new Paragraph();
paragraph.Inlines.Add(textElement);
rtb1.Document.Blocks.Add(paragraph);
rtb2.Document.Blocks.Clear();
//On this place I would like set start position for input text in rtb2 richtextbox on the start position
}
}
Thank for your advances.
If you really need your combined RichTextBox to have generalized document editing capabilities, what you are doing is probably the easiest and no, there is no pure-XAML way to do it.
On the other hand, if you are writing a chat application or something like it there may be a much better way to do it: Replace your combined RichTextBox with an ItemsControl that displays all the chat items as individual items. Then when Enter is pressed, add the text to a collection in your model. As long as the collection implements INotifyCollectionChanged, the new text will appear in your ItemsControl. And if the template you use for your ItemsControl allows editing, your user will be able to edit the item.
Which way you go all depends on what you're trying to accomplish.

Winforms Checkbox Focus Problem if no Text is Applied on Checkbox

I have a multiple checkboxes on a Winforms without having the Text Property of all checkboxes,
so the problem is that when i hover a mouse on the checkbox it highlighted but when i go to the checkbox using tab key it never get highlighted..
If anyone have the similar issue and already solved it Please help..
The problem is that when a check box gets focus it highlights only the text portion of the control which is empty in your case. You have a few choices:
1) For all your "blank" text boxes, set the text property to a space. This will create a small highlighted portion when you tab to the control.
2) Program the OnEnter and OnLeave events of the checkbox, and draw/paint a square around the whole control.
3) If you want the default MouseEnter behaviour which creates a yellowish highlight on the check box itself, create your own check box control as follows:
public class MyCB : CheckBox
{
protected override void OnEnter(EventArgs e)
{
base.OnEnter(e);
base.OnMouseEnter(e);
}
protected override void OnLeave(EventArgs e)
{
base.OnLeave(e);
base.OnMouseLeave(e);
}
}
I added an event handler for the CheckBox.Paint event and added the following:
private void checkBox1_Paint(object sender, PaintEventArgs e)
{
CheckBox checkBox = sender as CheckBox;
if (checkBox.Focused)
{
// e.ClipRectangle is affected by checkBox.Padding. Be careful when changing the Padding.
ControlPaint.DrawFocusRectangle(e.Graphics, e.ClipRectangle, checkBox.ForeColor, checkBox.BackColor);
}
}
I also adjusted the CheckBox.Padding to be 2, 2, 0, 1 in order to get a border that was 1 pixel from the edge of the CheckBox.
You can fix this by setting the AutoSize property = False. When AutoSize is True, it acts like a Label with AutoSize set to true, in that an empty label will take up almost no space on the screen. With AutoSize = False, you can manually set the bounding rectangle for the checkbox.
If you draw border only, try to set these properties.
AutoSize : False
CheckAlign : MiddleCenter
Font: Courier New, 12.25pt
TextAlign: MiddleRight
Padding : 0, 5, 0, 0
Size : 26, 26
Text : " " (two spaces)

Resources