I have a simple form containing a main view and also some text boxes and an "add" button that I use for adding data that is displayed in the main view (and stored in a text file). What I want to do is to add a little button that will toggle hiding/showing of the adding controls. Such button usually is a small square containing two arrowheads pointing up/down depending on the state. How do I do that?
(I'm sorry for the terrible title, but I don't know the proper name for this. Could anyone tell me?)
I don't think there's something built-in in WinForms for that. When I needed to do something similar, I just changed the Height of the form...
this.ClientSize = new System.Drawing.Size(required_width, required_height);
use a bool for hiding/showing
You can use the forms Height property and the controls could be hidden with Control.Visible = false
I think the word you're looking for is "Collapsible panel".
A quick google/codeproject search will provide you with some links:
http://www.codeproject.com/KB/miscctrl/TgXPPanel.aspx
http://www.codeproject.com/KB/miscctrl/XPCollapsGroupBox.aspx
http://www.codeproject.com/KB/miscctrl/CollapsibleGroupBox.aspx
I suggest you use a SplitContainer control and play with the Panel2.Collapsed property by sitting it to true or false
put the control that you want to hide/show inside panel2 and put the button in panel1. Change the Orientation property to Vertical, and there you go
Related
The problem is somewhat trivial yet I can't seem to find any standard solution to it.
I have a form where according to the user permissions I show or hide a button+textbox. What happens right now is this:
This is when the user has permission to see/use this. And when he doesn't :
It's not visible - the easy part, but from what I found out, only the FlowLayoutPanel offers automatic functionality to hide this empty space and my case is not that.
Set the Dock property to Top for the label and textbox. That way, when the button and textbox disappear, the layout system will move them up automagically.
It depends if this is a simplified version of your question. If it's only what you describe, whenever you check permissions/hide the relevant controls, you can just reposition the other controls using their Top property.
Wrap the control in a div and set floating to float:none. then, hide the div together with its content inside by setting the div display to none display:none. Eg;
<div style="display:none;float:none">
content to hide begin here
</div>
Well, its very simple, just change the location of that control to the location to the hidden control
and relocate it to the original location when not hiding the hidden control.
btn.location=new point(x,y)
where x, y are coordinates of the hidden control shown at winforms.
I want to show some information at textBox exactly at cursor's place.Not like in the intellisense at C# :it appears where "." inserted.Please help.At picture you see it appears according to dot(".") but i want to it appear according to that which i mentioned at picture(sorry my english is bad,and i couldnt find what that means .)
What you can do is, whenever the user presses a key inside the textbox, handle the OnKeyDown event, compute the current cursor position and repaint the popup control. This popup control can be defined by you as a custom control.
Edit: as jberger pointed out, you can also implement the handler for OnSelectionChanged, to handle any cursor change.
You can use a Popup: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.popup.aspx
This is essentially a window without border displayed above other content.
Assign PlacementMode.Mouse to the property Placement. There are several other properties to modify the popup position.
You can also use AdornerClass for creating your own custom-styled popup.
Check this link:
http://msdn.microsoft.com/en-gb/library/system.windows.documents.adorner.aspx
If you aren't used Adorner class yet, you can start with: http://msdn.microsoft.com/en-us/library/ms753340.aspx
Hey I was just wondering the techniques everyone uses to style radio buttons in winForms. I find them very plain, and would like to add some color or different images for the controls. The only way I can think of is to actually use a button that looks like a radiobutton, and set it to true or false.
Just wondering if there is a way I can do this, but still use the radio control.
Here is the RadioButton MSDN.
Here you can see that you can, like many Controls :
change the Button Apparence.
change the Button Color.
change the Button BackGroundImage.
There are many options to create your CustomRadioButton.
Here are two links which you can use to customize your controls
http://www.devexpress.com
http://www.dotnetskin.net
I'm suspecting the answer is no, but I just want confirmation before I move on - is there any easy way (as in, not re-templating) to hide things like the box that gets checked on a CheckBox, the drop-down arrow of a combo box, etc. without hiding the actual content being displayed?
Try this! Example is for a radio button:
radioButton.Visibility = Visibility.Hidden;
You can play some around with the Background or BorderBrush, but the answer is as you excepted: No..
You will need to restyle the control, but don't let the whole styling and templating scare you though.. Its actually quite easy once you get the hang of it ;)
Notice that you can have a checkbox like button using "ToggleButton", so you could use more or less use the same template as for your normal buttons (if you need them for toggling states).
The answer is YES, as you can actually template all controls a lot, without the need of creading custom controls. Just set the template in a style and add the style to the control.
oh i just reread your question
.. the answer is NO, but have a look at the toggle button maybe its what you are looking for.
the simplest way to display the content of ComboBox, CheckBox, etc. is to display a TextBlock in readonly mode.
You can easily make an UserControl with a DependencyProperty and show/hide your content.
You can disable the control/s in which case they cannot be interacted with but the text is still displayed.
I have a Panel and I am adding controls inside this panel. But there is a specific control that I would like to float. How would I go about doing that?
pnlOverheadDetails is the panel name
pnlOverheadDetails.Controls.Add(lnkCalcOverhead);
The control named lnkCalcOverhead is the control I'd like to float.
Thanks in advance
EDIT: By float I meant the css style not anything fancy :)
If you have a CSS class defined for the control, you could do this before calling the Controls.Add method:
lnkCalcOverhead.CssClass = "MyClass";
If you want to use the style attribute directly, try this:
lnkCalcOverhead.Style.Add("float", "left");
IF you are talking about System.Windows.Forms here (and not WPF or ASP.NET):
When you are talking about float, do you mean you want to position it anywhere you want by code? If so, just set the .Location property of the control.
If you are talking about letting a control be moved around inside the panel by the user of your program, you will have to code that. That means capturing mouse events and moving the control accordingly?
Alternatively you can instead of letting the control reside within the Panel, make it as a single control occupying a new form (hence you dont have to code all the mouse event handling). Just make sure that the window is limited to be moved within the boundaries of the "parent panel" (just check on the move event of the form if its within the boundariesm and force it to stay inside).