I'm adding buttons (with text and images) to a richtextbox control, but because I don't use the following line:
richTextBox1.AppendText(Environment.NewLine + str);
The scroll bar doesn't match the total number of lines, and doesn't resize properly, how can I solve it?
What is going wrong
I find this to be a very peculiar way of doing things. So first, lets add a little background:
When you use richTextBox1.Controls.Add(new button()) - what you are doing is: you are adding the new button as a child of the richtextbox, not as content - and this is the problem.
The scrollbars are set to read their height/scrollable area etc from the content of the richtextbox, and yours has no content, hence no scrollbar (or false readings etc).
You could create a custom richtextbox control that inherits its scrollable area from the location of its child controls. However, if you would rather avoid that route, please continue reading:
The correct way
I do not know your use case, so this may not work, but I would remove the richtextbox control and instead use a panel control. The panel control for example will update it's scrollbars based on child controls, whereas the richtextbox wont - and this should give you the behaviour you are expecting.
Related
I'm building a drag/drop application in winforms c#, i need to drag a usercontrol and drop it to a flowlayoutpanle.
everything works fine, except the drop location, the flowpanel sets the droped items side by side.
how can I set the droped item to the the exact cursor position?
I'll extend my comment to an answer.
The problem is not based on drag'n'drop. The problem is based on a semantic level. A flowlayoutpanel is used, to automatically arrange it's contents.
See MSDN FlowLayoutPanel Control Overview
The FlowLayoutPanel control arranges its contents in a horizontal or
vertical flow direction. You can wrap the control's contents from one
row to the next, or from one column to the next. Alternately, you can
clip instead of wrap its contents.
So the flowlayoutpanel-control does exactly what it's supposed to do. If you want to give the dropped control a specific location based on coordinates you want to use a normal panel. A normal panel will not arrange its contents automatically.
I have a multiline textbox in a WinForms application. What I'd like to do is always have the top line visible, even if it scrolls. Is there some trick someone knows to do this?
Fake it. Use two TextBox objects, draw your own borders. You will need to deal with wrapping to the next line yourself.
You could also copy the first X characters to a label so when the TextBox scrolls they can see the first line in the label.
Unless it is an essential feature I would try to cut it.
The simple answer; depending on the appearance you are going for is to use existing windows controls to get the effect you want.
You can use a label control above a textbox and allow the textbox to scroll.
You can use two textbox - the top with it's .multiline property set to false, while the bottom allows scrolling.
You could encapsulate this all into a user control for reuseability.
Beyond that, I think you'd be looking at a fairly large project to implement your control (or at least overriding the onPaint() event of the textbox) with the desired behavior.
I was wondering what is the best way to print entire content of scrollable control. I was trying to print a control in several ways, however all the time I was only able to draw visible content of control. So far I tried to use
PrintForm // there is nothing I can do with this because it requires a form not a control
I was also trying to use controlName.DrawToBitmap() method however this function captures only the visible area of control.
What is the best way to draw this kind of controls ?? I would like to avoid scrolling control's content in order to capture all control's element.
I would suggest that you create an invisible to the end-user form (for examlpe, position it at (-10000, -10000) and this form should have the size enough to display the ScrollableControl without scrollbars. This way you will be able to workaround this problem.
I need to create a custom control that has an expandable part as a panel and a textbox part. The expandable part is a panel, that will either be visible or invisible. But when the panel is visible/expanded directly under the textbox, I do not want the adjacent controls to shift down below the panel, but the panel should just overlay the controls that are there just under the custom control. How would I implement this in Winforms C# project?
I am open to using user control for this scenario.
Thanks
Sunil
I think your implementation of expanding and collapsing is not the best, because you are just overlaying the controls instead of hiding them.
One of the disadvantages is that the overlaid controls might by focussed by pressing tab and they might have a value which I think it is out of target.
I would suggest another implementation by creating two panels (one for the header and another one for the content) and when the collapse button is pressed then the content's panel will be hidden by sitting its Visible property to false and its Hight to 0.
How can I assign a background image to tabpage control in Visual Studio C# 2010? I am able to provide background image to each of the tab separately, but I cannot do it so for the whole tabpage control, due to which a portion of tabpage control remain with different background and each of the tab pages has ok and fine background.
Here is the picture of my form:
See the 'grey-colored' region in the tabs line. How can I cover the whole tabpage control with one single background?
The header area that contains the tabs is not part of your tab page. It's part of the parent TabControl, which is automatically drawn for you by Windows.
If you want to change how it looks, you'll have to draw it yourself. That's called owner-drawing, and it's not exactly a trivial undertaking, especially for a complicated control like this one. For starters, you can't just use OwnerDrawFixed, because that just allows you to custom draw the contents of the tabs (for example, to change the font). You will need to owner draw the entire tab control.
I can't imagine a good reason that you would ever want do this, but you'll find a few samples online that might help get you started. For example:
http://homepage.ntlworld.com/mdaudi100/alternate/tabcontrols.html
http://www.codeproject.com/KB/tabs/flattabcontrol.aspx