With reference to my previous question here: Changing Font Size for ListView Column in C#. I would like to know how to change the height of the column within a listView with OwnerDraw enabled.
I have succeeded in changing the font using the following code.
using (Font headerFont =
new Font("Helvetica", 10, FontStyle.Bold)) //Font size!!!!
{
e.Graphics.DrawString(e.Header.Text, headerFont,
Brushes.Black, e.Bounds, sf);
}
Although I cannot change the size of the column, giving it a cut-off effect. I have been playing around with the Rectangle.Bounds property but this appears to be read only.
Any suggestions?
Thanks
I have decided to take an alternative approach for my application. I chose to remove the header altogether and replace it with labels within a Container Panel.
This was achieved by changing the HeaderStyle property of the listView to "None". The result allowed me to dock the labels to the top of my listView, giving me the larger text I've been after!
Granted this is a little different to the question asked but provides a simple solution to what appears to be a complex problem! Additionally this would make the column headers static so may not be useful for developing applications requiring numerous changes
Thanks for all your help, and let me know if you would like more detail
Euan
You can try Better ListView Express. It allows changing column header height to arbitrary sizes. It is also free and the usage is 99% same as ListView.
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 trying to perform edit functions in a RichTextBox on a C# (Windows Forms) application.
I would like to be able to select any number of text characters in the script then change targeted font characteristics.
The trouble I have is that each characters font properties may be set to different font. In this case the textbox ignores the event that I request.
How can I solve my problem?
Take a look at this:
Changing font for richtextbox without losing formatting
I think it's the same issue. LarsTech's solution is working perfectly for me.
I have a code to change the size:
RichTextBox1.Font.Size == new System.Drawing.Font(RichTextBox1.Font.Name, yoursize)
And if you want to change only the selected text size:
RichTextBox1.SelectionFont.Size == new System.Drawing.Font(RichTextBox1.SelectionFont.Name, yoursize)
Hope it will help.
I have a combo box that has a list of font families in it. As you can guess I'm making a toolstrip for editing fonts in a rich text box control. The problem is when I change fonts it's resizing my combobox.
scrolling through different fonts causes the combo box to become "jumpy" and some fonts have a huge height which is causing for some hilarious problems.
Exhibit A:
Exhibit B:
Yeh... I'll show the code that I have so far... by the way the combobox is just bound to the font families collection.
void box_SelectedIndexChanged(object sender, EventArgs e)
{
String text = ((Font)box.SelectedItem).Name;
Font font = (Font)box.SelectedItem;
BeginInvoke(new Action(() => box.Text = text));
BeginInvoke(new Action(() => box.Font = font));
}
Anyone have any ideas, if I can't find a solution I can just stop the font from changing and just display the name in the default font.
Using a ToolStripComboBox is the problem here I think. The .NET 2.0 ToolItem classes have a lot of residual, erm, features that never got addressed. WPF sucked the resources away. The tool strip is obviously not handling the resize very well. Nor does it make the rest of the form move down when it gets bigger which is by design.
The canonical font combobox uses owner draw to display the fonts in the dropdown list in their regular style. Without changing the font of the box itself. You really don't want the toolstrip to resize, that's just not a great UI.
The only way I can think of doing it is by creating a custom combobox control and deriving from said control. This will give you access to the variable ownerdraw which gives us a little more flexibility without having to mess around with the ItemHeight property. Hooking into one of the events, which dictate that the value of the control has changed.
You could then have a function like the following to calculate the new layout size:
using (Font font = new Font(this.Font.FontFamily, (float)this.PreviewFontSize))
{
Size textSize;
textSize = TextRenderer.MeasureText("yY", font);
_itemHeight = textSize.Height + 2;
}
I tried all these approaches with little success sadly. However I didn't realize it until today when I looked at how microsoft office implements it. They actually use the same font in the combo box for the selected item no matter what font is selected. So as much as I want to make it more custom I'm just going to use a uniform font for whatever font is shown in the selected index.
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