How to change the z-index in c#? - c#

I have a rich text box that covers the entire form. Under that text box, I have a button, the problem is I need that button to be on top of the text box, so that I can click it. I did some research, and I think I have to change the z-index of the button, but I don't know how to change that. Any help would be great, thanks.

Right Click on the Text Box and click Send to back. Or alternatively, focus the button and click Bring to front.
Have a look at Introduction to Visual Studio .NET and more specifically at
Table 9. Order options under the Format menu
I might however recomend that you rather look at using SplitContainer Class.
Represents a control consisting of a movable bar that divides a
container's display area into two resizable panels.
Have a look at Windows Forms Controls Lesson 8: How to use the SplitContainer control

Related

Moving controls on a form onto a tab

I have been working for months on a project in c# in Visual Studio 2010 (it interfaces with a camera, power supplies, and motion control). There is a form with many controls on it (radio buttons, buttons, text boxes, bitmap displays...). Now I would like to put all of that on a tab so i can have another tab. This is so that the second tab can have all the default settings on it (e.g, portnumber, baud rate, integration times, pathname...).
Is this doable? Is there a way to cut and paste or click and drag?
Update:
I created a form, put a button on it that when clicked displays a message box with "Hello World". Then i added a tab control to the form, and dragged the button onto the first tab. The button still functions in the same way, displaying the message box when clicked.
So on my big form, i added a tabcontrol. Without resizing it, i did a select all, then unselected the tabcontrol, then dragged everything onto the tab. I then moved the tab control and resized it, then iteratively resized the tab window and moved all the controls. this worked, except the picturebox controls somehow got resized so they were larger than a screen width. Resized the pictureboxes and everything works. (perhaps i just needed the encouragement to give it a try...sorry if not the best question:).
To do this in code, in Form1.Designer.cs can add:
this.tabPage1.Controls.Add(this.button1);
However, I would have to do this for every single control (about 200 of them in Designer.cs).
This can usually be done with some editing of the .Designer.cs file. First, make sure you make a backup in case it all goes horribly wrong. Place the tab control and add a single control (a button or anything) to it. Then examine the .Designer.cs file. As you point out yourself, you will see a line like this:
this.tabPage1.Controls.Add(this.button1);
As for the existing controls on the form, there will be a bunch of lines like this:
this.Controls.Add(this.meErrorReport);
this.Controls.Add(this.peWarningSign);
this.Controls.Add(this.meHeaderText);
this.Controls.Add(this.btnClose);
So what you do is to cut these lines (not including the one for the tab control!), and paste them just following the line shown above, and do a find-and-replace to change them so they match the first one:
this.tabPage1.Controls.Add(this.meErrorReport);
this.tabPage1.Controls.Add(this.peWarningSign);
this.tabPage1.Controls.Add(this.meHeaderText);
this.tabPage1.Controls.Add(this.btnClose);
This should usually do the trick. The controls may be positioned wrong, and most will be hidden until you increase the size of the tab control, but these are minor problems that can be fixed.
PS. I know you've already fixed your problem, but I'm posting this answer in case it can help you, or someone else, in the future.

Perform some action when tabbing between labels?

I know that label can't receive focus, it doesn't seem to be responsive to tab switching. But all I need is perform some action when user uses tab consequently on a form which has only labels. For example, each label has an associated textbox but this textbox is hidden when the label is visible and vice-versa. What I want is allowing user to use tab to switch between the hidden textboxes on the form, normally, all the textboxes are hidden while all the labels are shown, the labels are supposed to be focusable so that when using tab, it can know that (as some event) to show the associated textbox and hide itself, when switching to another label, the current label whose the associated textbox is shown will become visible again and its associated textbox will become hidden.
I have to implement this kind of 2 in 1 control (textbox and label in a composited control) because I just want to show only the text (no border and background) as if the textbox has a transparent background and only show the textbox (and hide the label) when user need to edit (start by clicking on the field or using tab). This should have been easier for me if there was a transparent background textbox but there isn't a decent one in the world of windows forms. Please notice that I also know of the alpha blend transparent textbox presented in an article in codeproject but it can't meet my need because the text is rendered wrong with ugly border around the text path (some kind of missing antialiasing but it's even worse than that).
I'm really pity if this mechanism can't be implemented, the forms look better when all the fields seem to show info only but a click or tab switch can let user jump in edit mode.
I hope there is some solution out there. Thank you in advance.
I found this solution by a whim in my mind. I didn't think there was such a solution but it does help solve my problem (and I'm sure many others will benefit from it). Simply I have to create my own Label inheriting UserControl. I didn't thought of UserControl before and it is very helpful. Focusability, transparent background, borderlessness are all which can be done easily to a UserControl. The only custom feature I have to do myself is rendering the text which is also very simple and there are many ways to do. I just add a Label to the UserControl and set Label's Dock to DockStyle.Fill, adjust the height of the UserControl properly and that's all.
Thank God helping me think of UserControl before trying any other complicated solution such as listening to TAB and SHIFT + TAB keypress events.

Make Multiple Controls Use Same Tool Tip Message (c# Client App.)

I would like the same tool tip message (the one entered in the "ToolTip on myControlId" field) to be displayed when the mouse is hovered over an area which contains multiple controls. I tried putting the controls inside a Panel and GroupBox, but it only works when the mouse is in the "white space" area of the Panel/GroupBox, and, of course, does not work when the mouse is on a control within the Panel/GroupBox.
I'm from the web dev world so I'm open to suggestions for a new approach if I'm going about this the wrong way.
In standart windows developmern (WindowsForms) tootltip or tooltip control is associated to a single control. But you can use ToolTip control (see example how: ToolTip: Windows Forms .NET) and assign to all controls that recieve mouseover event.
If you're in WPF, the story becomes easier as you have message routing so usually it's enought to have subscription in one place.
Hope this helps.

Silverlight Scrolling Tab Control

I am wanting to create a sivlerlight tab control where the tabs remain on a single line and scroll buttons will allow me to scroll left or right through the tabs. Below is a link to a control that can be purchased but I would like to write my own and share it with the community. I know I can create a inherited class and style with buttons for the tab control. I guess I am confused on how to keep the tabs on one line and scroll the tabs so only half of a tab would be shown. Can you all help with this? If I way off base please correct my direction.
Sample tab control
Recently I have created the TabControl in which the tabs are situated on the single line.
I have written the blog post where I've explained some details.
Also you can download the project directly here.
My first instinct would be to create a control that has a ScrollViewer with a WrapPanel inside it (from the Silverlight Toolkit) that is flowing horizontally. Then you can add the tab buttons to the flow panel and you should have the scroll behaviour.
Of course, if you don't want a scroll bar but instead want buttons, you can do the same thing but hide the scroll bars, then embed the whole thing in a Grid with three columns. Have the ScrollViewer sit in column 0 with a columnspan of 3 and then add a button to columns 0 and 2 that you can show and hide when the mouse rolls over that cell of the grid. You could then somehow scroll the viewer when the buttons are pressed.

C# Dropdown Slide Form

Is there any built-in control like a dropdown/slider? For instance, I want to display some info on dialog/control/form and inside that form there is a arrow which expands it to show more information?
alt text http://img227.imageshack.us/img227/4945/73068794.jpg
When I click the black arrow, the form should expand vertically to show more info. That's what I want to achieve. If there isn't any built-in control, can you please tell me what do I need to do to implement it myself? And how can I add a little animation when it is expanding?
Like here (when you click the menu header it doesn't expand/contract instantly rather it does little slowly, that's the kind of animation I would like to add)
This CodeProject article should help you get started.

Categories