Filling the empty space left from hidden controls - c#

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.

Related

How to show anything(e.g information) like popup according to cursor's place?

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

Hide/show part of the window with a button click

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

Managing Lots of Overlapping Controls in Visual Studio

I'm using different sets of controls on the same location on a form. By default all are visible=false and then certain subsets of the controls are set to visible as the user selects specific values in a combobox dropdown control.
From the user's perspective this works well since they only see the controls that are needed.
However, since the controls occupy the same location on the form it is difficult to manage these in Visual Studio design view.
Is there a way to group sets of these overlapping controls in Visual Studio so that I can select the entire subset of controls quickly and easily? Is there a way to hide certain controls in design view? Right now everything is stacked on top of each other when developing so it makes managing these controls difficult.
To get such a beast to work i would put every group into it's own UserControl. On your MainForm you stack all these UserControls above each other.
So at the MainForm you can't really get a good overview, but now you got for every group your individual designer view and in your main form you can hide the complete group by a single line of code userControl.Visible = false.
A TabControl can do this, works well in design mode. You just need to hide the tabs at runtime. Check my code in this thread.
You can not hide them.
However you can group them in group box
and using "Bring to front" and "Send to back" property deal with them.
First of all,
If you work with multiple components in same location, you can use groupboxes in your form. Then, to superimpose these groupboxes, you should edit each of your groupboxes on different place in your form screen. After the edit, you should input size and location data manually in your groupbox properties menu.
If you want to edit one of your groupbox after the set location, you can easily right click any of your groupboxes then click "send to back" and "bring in front" commands. I hope it helps.

HTML divs popup to select columns

I have a web application(ASP.NET2.0 C#) and in it, I have a gridview that gets its data from a datasource.
I wanted to add the following feature: the user can click a button "select columns", and a box pops up with a list of all the columns(a checkboxlist in a div, possibly) and that way, the user can choose the columns they want to see, and click another button "show" and the list of columns goes away, and the table shows the columns that the user selected.
I have already implemented the column choosing part, but it is the popup part that I need help with. How can I make the div popup and then disappear?
The solution might require javascript, and I might not have figured it out since I don't really know javascript that well.
Thank you.
HI,
Its better to make the display of div to be none rather than setting visibility to hidden. If visibility is set to hidden even if the div doesn't show up but it will take the rendering space which in some situation might not be that good.
You can dynamically create a div using createNode and then by absolute positioning and setting the top and left according to your convenience you can align the div to any portion in the page. Its better if you could disable the background when the div pops out.
Create the div and set visible=false. When you want to pop it up write the javascript to set it visible=true.
here's a good pointer http://lists.evolt.org/archive/Week-of-Mon-20020624/116151.html

C# Adding style to a control

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).

Categories