So in winforms, every dropdown combobox has this little arrow thingy to the right that tells the user it's a dropdown, kinda like this:
Now how do I figure out how wide that is in pixels? Reason is, I'm using ControlDrawToBitmap, this doesn't draw the text properly for the combo boxes, and I can redraw the contents, I just whack some of the arrows (which are drawn properly).
First idea that comes to mind: Check to see if the combobox button width tracks with the scrollbar width. The scrollbar width can be modified in user preferences. Use GetSystemMetrics() API to get the width of the various scrollbar pieces. If you change your system scrollbar width and it does not affect the size of a normal combobox, then ignore this.
Second idea: use the edit control's formatting rect to find out what the edit control thinks is the usable display area (minus the combo box). See EM_GETRECT in MSDN.
However, it sounds like this is just a hack workaround for your real problem: If you could get the controls to draw correctly to bitmap, then you wouldn't need this hackery.
I calculated it to be 9 pixels wide in photoshop
Related
We need to show our disabled comboboxes as an image. The image has the same height as the standard combobox, but for some reason it cannot override the borders of the combobox.
Instead, it end up looking like this:
We would like them look like this image, i.e. that the image is shown on top of everything - including the combobox borders:
Any ideas?
Thanks.
First of all, what you are trying sounds really dirty - the best way would be, if your ComboBox would just look like your image as soon as you disable it!
If there is really no other way:
Create a PictureBox in front of your ComboBox. Set the image as the PictureBox's image, make it Visible whenever you want to "disable" your ComboBox.
But again, using controls to simulate behaviour you would expect to be part of another control is dirty.
Get the location of you textbox, set it invisible, then a the same location place an imagebox
I want to make it so that my buttons change size based on the text inside them. Kind of like a Label with it's height and width set to "Auto", but I would like to start with a pre-determined dimension.
Is there a way to place a button, size it, and allow for re-sizing based on run-time text changes? If so, how do I do this?
I've looked at this example:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/188c196e-90d8-4584-bc62-38d7e008cf5c/how-do-i-resize-button-text-upon-button-resize
It has to do with inserting a textblock on top of the button, but when the text adjusts sometimes the new text becomes too small because the text does not wrap for some reason...
Thank you.
You can set the MinWidth and MinHeight properties so that you start with a predetermined size and the button will be able to grow with text.
Unfortunately this would not allow the button to get smaller.
You will need to size it based on its content, then. That is, have no XAML defined size.
Elements on the page normally size themselves to their children.
I have set up a ToolStrip in my C# WinForms project and have added a TextBox on it. I'm just curious whether it is normal that the TextBox is barely visible due to the colour of the ToolStrip and TextBox.
I could put a border around it or change the background colour of the TextBox but that just looks odd.
Is there some property which I haven't thought of which I could set to make it stand out more but not look out of place?
Screenshot added:
A very light border would probably be best. if you use the same color as the toolstrip, you won't really notice the border at the bottom, but it will make the top of the search box stand out. you might also want to add a margin around it, or less padding inside of it, so it doesn't fill up the whole hight.
I'm using TabControl and I have DrawFixed. I just want only draw the tabs not the panel under it.
How can I remove it?
Also I'd like to ask, can I change tabs size? I've long text which I'd like see all if it's selected but I'd like see it cropped if it's not active.
I've following in draw event, but it always draws the tab in the same size.
if (e.State == DrawItemState.Selected)
{
e.Graphics.FillRectangle(Brushes.White, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
}
else
{
e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
text = text.Length > 10 ? text.Substring(0, 10) + "..." : text;
}
e.Graphics.DrawString(text, e.Font, Brushes.Black, e.Bounds.Left + 17, e.Bounds.Top + 3);
Thanks in advance.
Chronologically in your question, you have asked how to get rid of that bar at the top. If you insisted on using 'faux' tab pages where the tabs merely control content of the fixed set of controls, then shrinking the height of the tab control to a point where that isn't visible is probably an acceptable solution. I just tried it and with some tweaking it looks mostly what I think you are after. For the record I'd recommend actually using the tab pages as intended, that is as hosts to controls, even if you make a custom control that brings together all the controls you want visible. This will fit the tab paradigm much better.
For the second point you'd like to resize the tabs. Impossible. The framework gives two options for DrawStyle, Normal and OwnerDrawFixed. Normal allows Windows to set the tab size based on the text and font, OwnerDrawFixed means the tab size is completely fixed. There is no more control over this. OwnerDrawFixed however gives you access to the OnDrawItem event which is what you are wanting to use for painting the tabs themselves.
It now seems you've bitten the bullet and set UserPaint to True which means you are now doing all of the drawing. I recommend at this point to set DrawStyle back to Normal, then you can kludge some behind-the-scenes text to have Windows control the tab widths automatically. I will warn this won't be very robust since everyone has different font settings and a few pixels off and nothing will draw right.
So here I'll point out TabControl.GetTabRect(index As Integer), the method you can use to get the bounding rectangle of a given tab. I use this in a loop over all the tab indices and then do all the drawing I need for the tab within the rectangle provided from each tab. This means I don't need to use OwnerDrawFixed to get the bounds to paint within.
However still if you want better control, you're 80% the way to just implementing exactly whatever control you want to see, starting from either Control or UserControl. A similar look could be achieved from overlapping buttons with some logic to paint and lay them out. Then you could get all the text appearance you want also. I considered the same myself but didn't because I am still hosting TabPages. Since you're free from that it would be even easier...
Just use page text default property it will auto fix tab size for you according to the size of text.. then paint your text by your self .. if you still want additional space for painting image or some thing else then use padding which is the property of tab control not the tab page. i hope it will help full for you.
In my Winforms application I have a toolbar that contains many items (buttons with icon 32px, labels and comboboxes).
I decided to set the Toolstrip.LayoutStyle property from the default HorizontalStackWithOverflow to Flow in order to allow the toolbar split automatically on more rows when user have a very low resolution monitor or he/she resize the window.
The problem is that all labels and comboboxes are aligned to the top of Toolstrip when I change the LayoutStyle.
Does exist a property or any other workaround that allow me to center them vertically?
I think I see what you mean, the label isn't as tall as, say, a button. And it gets aligned improperly with LayoutStyle = Flow. Ugh. You can work around it by changing the Padding property of the label. To do this properly, you should however do this in the form's OnLoad() method override, the label will be taller when you run on a machine with a higher video DPI setting.