Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Control.Visible Property Problem
 

Control.Visible Property Problem

Hi,
In my application I have developed a visual component with a panel and some controls on it(buttons, picture-boxes etc.). I want to make some parts of the components invisible according to some needs.So I am making those controls' Visible property false. The problem is I am using this component in several forms however when I build the project all controls' visible property becomes true again.Component does not remember state of the visible property.
How can I solve the problem
thanks..
silence__  Friday, April 20, 2007 7:42 AM

Hi :

dose your visual component means a user control?

I suggest you put visiable property into the constructor of this component.

like follow

Code Snippet

System;

System.Collections.Generic;

System.ComponentModel;

System.Data;

System.Drawing;

System.Text;

System.Windows.Forms;

Test2

public partial class MyTextBoxAndButton :Panel

{

private TextBox TB = new TextBox();

private Button BT = new Button();

public MyTextBoxAndButton()

{

this.TB.Visible = false;

this.Width = 200;

this.Height =this.TB.Height;

TB.Width = 150;

this.BT.Width = 50;

this.BT.Height = this.TB.Height;

TB.Location = new Point(this.Location.X, this.Location.Y);

BT.Location = new Point(this.Location.X + this.TB.Width, this.Location.Y);

this.Controls.Add(TB);

this.Controls.Add(BT);

this.BT.Click += new EventHandler(BT_Click);

InitializeComponent();

}

void BT_Click(object sender, EventArgs e)

{

MessageBox.Show("Click");

this.TB.Visible = true;

}

}

Bob zhu - SJTU  Wednesday, April 25, 2007 3:57 AM

You can use google to search for other answers

Custom Search

More Threads

• Visual Studio IDE Hangs with Databases that has several Master-Detail Tables....
• Behavior, OnMouseUp event and the Point
• OnDestroyHandle() Question
• Please help me!
• problem with AddRange()
• EditorAttribute constructor resolution
• Size's Required by my forms keep changing Why???
• how to debug a control as it's loaded into control/resource/forms editor
• Resize panel in winform
• Custom control displays differently in TabPage