I'm working on a form in Visual Studio 2012. There are multiple labels ranging from Label1 to Label10 arranged vertically. I need to copy these labels next to the first set of labels such that I have Label11 to Label20 next to the first set. However when I copy/paste the form elements they are pasted vertically in a reversed sequence i.e Label20 in front of Label1 and Label19 in front of Label2, I don't want the sequence to get reversed when I paste the form elements.
I remember it working fine when I tried it on VS2015, but now I'm on VS2012 and it doesn't works as expected. Based on Google search results this doesn't appear to be a common question.
This depends on the z-Index of your copied controls.
If you add 2 new labels with the VS designer to your form in InitializeComponent() will be this code:
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
If you copy and paste them it will result in:
this.Controls.Add(this.label3);
this.Controls.Add(this.label4);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
where label3 is the copy of label2 and label4 is the copy of label1.
If you fix the z-Index of your labels (right-click on them in the designer and use 'Bring to front'/'Send to back') it will become:
this.Controls.Add(this.label1);
this.Controls.Add(this.label2);
Now, when you copy and paste them you'll get:
this.Controls.Add(this.label3);
this.Controls.Add(this.label4);
this.Controls.Add(this.label1);
this.Controls.Add(this.label2);
where label3 is the copy of label1 and label4 is the copy of label2.
Btw, this behaves all the same in VS2010, VS2012 and VS2015
Related
When designing a WPF application in Visual Studio, I often need to move big chunks of code, for example, to change the order of big, nested controls. Before doing it, I often collapse everything with CTRL+M to make this operation easier. I select the collapsed code chunk that I want to move, and press CTRL+C.
However, as soon as I press CTRL+V to paste the code in the clipboard, the editor automatically expands it with all it's nested controls. Then I have to scroll miles up the editor to get back to the "-" sign in order to collapse that section again.
It is very annoying. How can I disable this behavior, so that the pasted code remains collapsed?
I have a TreeView (System.Windows.Forms.TreeView) control on a custom control (similar to the Output window in visual studio 2013). that control is placed at the bottom of a main form (like the visual studio ide). when i populate this TreeView control with data, it fills correctly, but, if the containing control is close to the bottom, the displayed "popup" is cut off. if i expand the lower control to have more room, the control displays with all the data. the display is "docked" to where it was designed. i tried putting a scrollbar on the display (which worked), but this is not the desired/requested behavior.
what i would like to do is to either have the display "go up", if necessary, like the "Show output from:" display on the Output window in Visual Studio 2013, or, simply have the display be FreeFloating.
any suggestions would be greatly appreciated.
thanks in advance.
pete.
RESOLVED:
- create 3 new variables ... originalParent, originalLocation, and firstTime.
- in the Resize method (which is called from a mouseOver event), where the size of the display is set, if this is the first time, save off the above and set the parent to the TopLevelControl
- determine the new location on the form ... originalParent.FindForm().PointToClient(originalParent.PointToScreen(originalLocation).
- see if the displayed output would go beyond the end of the top form ... TopLevelControl.DisplayRectangle.Height - (locationOnForm.Y + oTreeView.DisplayRectangle.Height)
- if the difference is less than 0, adjust the new location.Y by the difference.
- set the display output Location to the new location
presto ...
also, added a method so that when the main form is resized, or the containing control is repositioned, the location is set using the info above - just not adjusting for the display output height.
add a call to the reset in the mouseLeave event
I am working on a little school project and I have to use Visual Studio C++/CLI with Windows Forms Application.
Since I am new to Windows Forms I am having some difficulties.
What I would like to achieve:
Press a button
A PictureBox will be created at starting position
A timer will move the PictureBoxto some given position
Pressing the button again will spawn a NEW PictureBox with a different name which will begin to move in the same direction as the first rectangle
and so on.
Note: These pictureboxes have to have a different background color which must be randomly chosen out of 3 colors.
What I need to know is....
I know how to move a picturebox, but how do I dynamically create one with a custom name and color after a button press?
Thanks in advance!
Because you mention this is a school project, here is some high-level advice:
You can draw on a form by either subscribing to the Paint event (https://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint%28v=vs.110%29.aspx) or overriding the OnPaint method (https://msdn.microsoft.com/en-us/library/system.windows.forms.control.onpaint(v=vs.110).aspx). Take a look at the Graphics object in the EventArgs.
When the timer elapses, make adjustments to local variables (keeping track of the desired position of the Rectangle) and then call Invalidate() (https://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate(v=vs.110).aspx) to force the form to be redrawn.
I hope this helps you get pointed in the right direction.
I really, really want your help. My project is next.
I have a pictureBox1, which is parent for all other pictureBoxes that I create with array. These pictureBoxes are smaller that I can move them on the pictureBox1.
For every newly created pictureBox I set next properties:
PB[i]->Parent = pictureBox1
PB[i]->BackColor = Color::Transparent
At the same time I set to them PNG file, whose backcolor is also transparent.
With a single pictureBox on pictureBox1 it is OK. But when two or more pictureBoxes are located together they just block each other's content. I tried to bring to the front, but it ain't work. Which pictureBox is on top it blocks pictureBox below it.
How can I set or make a mutual transparency for pictureBoxes, while their parent is one, pictureBox1?
I've got a menu strip, inside which I want to embed my company logo and align it to the right.
My project is on a Windows Form Application, sorry for not including this before.
Several google-trips have found little, this is probably my not using the proper terminology.
What is the best way to do this? I'd also like it to be flexible, so preferably no fixed-position methods.
Thank you.
Dock a TableLayoutPanel to the Top of the Form. Make it have one row and two columns. Put your MenuStrip in the left column, and a PictureBox in the right column for the Logo. Set the right column to AutoSize, the Row to AutoSize, and the TableLayoutPanel to AutoSize. Also set the SizeMode of the PictureBox to Autosize.