Show outline of empty label in Visual Studio - c#

I am working on a XAML page in VS2012.
The page has a couple of empty labels (which programatically get filled in later). Because the labels are empty, they do not appear on the page unless moused over.
Is there any way to have VS show me the outline of these labels only in the design pane (so in release it would be invisible).

First and foremost, the comments are correct - you should fill the controls in with dummy values and then clear them on startup (either automatically with databinding, or otherwise).
Now, to actually answer the question, you can check if Visual Studio is in "Design Mode", and then programmatically set the border of a control... or better, set the text to something easily noticeable in the UI:
// Check for design mode.
if ((bool)(DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue))
{
myTextBlock.Text = "*** DESIGN ***";
}
This code should be run in the constructor of your WPF window/control class (or something invoked from the constructor) so that the designer executes it.
The code to check for design time was taken from this post.

Related

How to clear default text from label in visual studio without making the label disappear visually

I wanted to remove the default text from a label in Visual Studio so in the design view I tried to delete the default text from the text property. But when I do so I cannot see the outlines of the label as a result, so I cant keep track on my labels or even access them anymore after deleting the default text.
I'm using Visual Studio Community 2015 and it's a windows form application template using Visual C#. Basically what I'm trying to do is to use labels for showing output on the form, and I don't want the labels to show anything until a button is clicked.
Thankful for any help on this!
You can have two options
You can set the values of the labels to a blank string in code on form startup i.e. lblName.Text = ""
You can remove the default values and give your labels a fixed width to see the outlines in the designers. The reason you do not see the outlines is that the label adjusts its width to the content within.

User control Anchor property issue

Context :
I created an User Control. For some reason, I want to use this control in different size. To keep the initial "Template" of my User Control when re-sizing, I use the property Anchor on my different element inside the control.
So when I create my control at design time, it is possible to me to hand re-size the control and keep the original "Template" of it.
When the control is created, it look like this :
And after re-size :
As you can see, the property Anchor work well.
The label and the picture stay in the middle.
The "?" stay to the left corner.
The problem :
The problem I have is, when the control is reloaded, created with a different size as the initial one, all the elements inside return to their initial position :
I don't know if this is the better way to do what I try to achieve. Keep in mind that I add and re-sizing the control's during the design time.
Thank you.
EDIT :
I think my problem is caused by the designer. Ex : I add my control in the designer, I re-size it, I run the solution. All is working good. But when I go to the code of the page, and then, return to the designer, the element inside the control returned to their initial position.
EDIT 2 :
Ok I have found a solution, I simply moved all the element of the User control inside a Panel. For some reason that I can't explain, it work perfectly. The control's stay at the same location.
The solution is ta add a Panel to the User Control and dock it to "Fill", then place the element inside of this panel. For some reason that I can't explain, the designer keep the location of the re-sized control's elements.
The anchoring, docking and auto-sizing of a UserControl seem to be terribly confusing. I found UserControl does not auto resize with the Form which suggests that you set the AutoSize property to False, which I did, and it still didn't correct my problem. But when I tried your solution, I also noticed there are two copies of the AutoSize property! I had set the AutoSize in the UserControl designer to False, but the Form designer where the UserControl instance was added also had an AutoSize on the instance, and that one had a different value (it was still True). When I set that to False also, then everything worked (with the panel in place). Then I removed the panel you suggested, and everything still worked. So I guess the trick is to make sure you check all the properties of the UserControl in the UserControl designer and in the form designer where the control is used. Then you shouldn't need a panel.
I've had similar problem in VS2015 project, and unfortunately - none of your answers helped. Clean and working solution was found here, in Jignesh Thakker answer.
For quicker navigation here it is how it was done in my project (c++/cli, not c#, but idea is the same):
System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
/* some code */
myUserControl = gcnew MyUserControl();
myUserControl->Dock = DockStyle::Fill;
tabPage1->Dock = DockStyle::Fill;
tabPage1->Controls->Add(myUserControl);
/* some code */
}
Set the Localizable property of the parent form at VS designer to false. This solves the problem at design time. (Save, close and reopen the form after switching the property)
If you need a localized application switch the Localizable property to true after finish up working at the layout and don't care about the wired representation in the VS designer. At run time it's shown correctly.
Tested in VS2013

A C# list of custom childs similar with android ListView

I need to create a list in c# with click-able and customizable child elements.
Check attached image (red square) to get a feeling of what I would like to end up with. I tested on a control called "list view". I can add an icon and a label, it is not enough, I need more customization.
So question: Which c# control should I use? Maybe share a link if you know something useful.
Note: I don't really know or enjoy C# (I am Java guy), as IDE I use Visual Studio C#, express edition and I would love to minimize the coding part as much as possible
First, create a user control (says ContactRow.cs)
Draw what ever UI that you need on it. (Image, text, etc)
Secondly, Create a container form (says ContactList.cs)
Add a TableLayoutPanel (Or FlowLayoutPanel Or equivalent) into container form.
Set AutoScroll property = true so that it scrolls.
In run time, you can new an instance of your ContactRow.cs and set all the values.
Then add it into the TableLayoutPanel using the TableLayoutPanel.Controls.Add(contactrow)

Custom MessageBox in C#

I am making a custom MessageBox in my own language (Persian). I want to know which component may I use for the text?
Label is not multiline and TextBox is a little bit not appropriate.
Which component does Visual Studio use itself?
What is the component I specified in the picture?
You can use a label. It has a number of options for laying out the text... One way is to set it to "AutoSize = True".
I support the answer of RQDQ, labels could be enlarged to occupy more than one line.
They have a property named TextAlign. When set to LeftCenter or MiddleCenter you could simulate the behavior of text in a message box. If the text doesn't fit in a single line, the label wraps it automatically on another line. However in this case I will let the property AutoSize to its false default value.
It all depends on what kind of Visual Studio project you are doing. Wpf or Silverlight or Asp.net or even windows, everything will depend upon which kind of project it is.
That looks to me like the MFC style label with an image, or in a browser it would be done with javascript.
You Can Use RichTextBox. I Use it For My Custom MessageBox And it works Correctlly

System.Windows.Forms.GroupBox text is missing

I am working with Visual Studio 2005 (C#) and in one of my windows forms I have a couple of textboxes. I have placed the textboxes inside instances of 'System.Windows.Forms.GroupBox' because I want to use the GroupBox member 'Text' to tell what the textboxes are for (it shows up as a label near the top left corner of the fine line that encircles the GroupBox).
My problem is that suddenly one of these labels just disappeared. It is present when I work with the form in the designer but when I run the program and the form appears the label is gone.
Thank you for any information on this issue!
Check to be sure you're not setting the .Text property of the GroupBox to an empty string.
If you do not need to access the groupbox in your code you can always set the property GenerateMember on the groupbox to false and what you see in the editor "should" always be what you get when you run the app.
This is useful with any controls that you do not wish to modify during runtime thus keeping your memory allocation down as well as mistakenly modifying one of it's properties as well.

Categories