My DropDownList won't keep the size setted in the CSS.
When the input is focused, the size is larger than expected.
Otherwize, the size is good.
What should I do for keeping the size of the DropDownList at the good size even if the input is focused ?
Thank you for your help.
You can use the css :focus
input:focus {
//set the style the same as your input while not focused
}
I used this: onmousedown="$(this).focus()"
Related
I'm trying to create a dynamic form. I found this on the web:
http://csharp.net-informations.com/gui/dynamic-controls-cs.htm
and it works. However, I needed to do it with a combo box and it worked, but, I couldn't resize it. Here is my code:
Code
Any help will be appreciated. As you can see, I tried to resize it before placing it on the form. No compile error. I don't know.
The height of the ComboBox is automatically adjusted to the specified size of the font. You can't change the height unless you increase the font. Like this:
box.Font = new Font(box.Font.FontFamily, 16);
So I'm making a C# Windows Forms application in which I have a label. This label's size is 100x100 by default*, but I want to automatically increase the label's height so that any string fits in it regardless of its "height". How would I do this? I haven't tried anything myself yet because I don't really have an idea of what to do. I'm just a beginner, after all!
Thanks in advance.
*100x100 is just an example, the real size is different (I'm not sure yet what it'll be)
Thanks everyone, I managed to get what I want by setting the label's MaximumSize property. (Answered by #LarsTech in comments)
AutoSize defaults to true - so the default behaviour of the textbox should resize to any font size/content that is in use.
The label control in Windows Forms is a container which accepts your input strings. Therefore, if you do change its initial values it will get to its content size anyways. So, just change its Text Property.
You could try it first.
here's an example code you can use. It uses the AutoSize property.
If you label is called Label1 you can change it like this:
Label1.AutoSize = true;
Label1.Text = "The text in this label is longer than the set size.";
And it will automatically change it.
I am creating a custom control in C#, and want to have a grid cell that contains a ListBox, which can be hidden or shown as desired. Hiding it is easy, I just set the Width to zero, however when I want to show it, I need to know the width that the ListBox would like to use.
I thought that DesiredSize.Width would give me this vale, but it's always zero, even after calling Measure(). Here is the code I'm using to show the ListBox...
_lb.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
_lb.Width = _lb.DesiredSize.Width;
Any ideas how I find the desired width?
If your ListBox is in the cell of a grid, give that grid column a name. Then in code, you can access the .ActualWidth property of that grid column and use that value to set the width of your ListBox.
That assumes of course that the width of your grid column is not set to Auto, because that would still give you a 0 value.
_lb.Width = myGridColumn.ActualWidth
You might need to subtract a little bit from the column width to make your control fit nicely.
EDIT
One thing that I've found is that the ListBox must have items added to it before it will return anything other than 0 when it is measured.
string myItem = "Don't ask for a bath in Athabaska";
_lb.Items.Add(myItem);
_lb.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
double width = _lb.DesiredSize.Width;
As long as the ListBox has already been added to the window/usercontrol/grid, the above code returns a value of 227.53 for the width variable; using my defaults for font family and size.
If the ListBox has not been added to the window, or it doesn't have any items in it, it will return 0 for the .DesiredSize.Width property.
Also, if the .Visibility property is set to Collapsed instead of Hidden, the width will be 0.
Don't set the width to 0 when starting. Leave the width alone initially, set the .Visibility to Hidden. It will render to the needed width, but won't be shown. Then you can measure it and start playing around with the width.
I have a drop down list in asp.net. I want to increase its height. please suggest, how to icrease it.
There is a height property on the drop down list.
myDropDown.Height = 200;
BTW: There is pleny of information around on how to do it:
http://dotnetslackers.com/Community/forums/asp.net-dropdownlist-item-height/p/3151/31235.aspx
http://www.vbforums.com/showthread.php?t=419074
http://forums.asp.net/t/1300753.aspx/1
If setting the height property is not helping you,
One way of achieving this by increasing the font of the dropdown as it gets set based on the height of its contents.
Or you could set it via css (not sure will work in all browsers)
Please edit to describe your current scenario with some code
Set the Height property of the control
I am trying to right align a control in a StatusStrip. How can I do that?
I don't see a property to set on ToolStripItem controls that specifies their physical alignment on the parent StatusStrip.
How do I get Messages drop down to be right aligned? http://i.friendfeed.com/ed90b205f64099687db30553daa79d075f280b90
Found it via MSDN forums almost immediately after posting :)
You can use a ToolStripLabel to pseudo right align controls by setting the Text property to string.Empty and setting the Spring property to true. This will cause it to fill all of the available space and push all the controls to the right of the ToolStripLabel over.
For me it took two simple steps:
Set MyRightIntendedToolStripItem.Alignment to Right
Set MyStatusStrip.LayoutStyle to HorizontalStackWithOverflow
As an added note this is due to the fact that in the Win32 API a cell is either fixed width or fills the remaining space -1
int statwidths[] = {100, -1};
SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Hi there :)");
If memory serves me correctly you can have only one fill cell (-1) per statusbar.
You could also add a third middle cell and give this the fill property to get a more concistent looking StatusBar. Consistent because Messages has an inset to its left right where you'd expect it. A bit like the mspaint shot found on the MSDN page for StatusBars
I like the creative appreach though :D
You can display the Button at the end of the StatusStrip by using the logic below.
Add a ToolstripLabel to the StatusStrip
Set text as string.Empty
Set Padding for the ToolstripLabel
For example:
this.toolStripStatusLabel1.Padding = new Padding((int)(this.Size.Width - 75), 0, 0, 0);
Keep a Toolstrip label , set Spring property as true and for label align text in BottomLeft
I found that you can set the StatusStrip Layout to HorizontalStackWithOverflow.
Then, for each control on the StatusStrip that you want on the right side, set the control Alignment to Right.
I like this better since you don't need any extra or dummy controls to align.
If you set a status strip label control’s Spring property to true, then that label takes up any space not used by other controls in the StatusStrip.
Set the RightToLeft tool strip property to True.