|
Actually the user control that i have to develop is a combination with two panels one below the other. and the first panel has a buttons and a label on it. Now when ever the button click happens the panel that is present on the down should visible and invisible alternatively.By default it is in 'visible' state.
This is the user control.
And now when i use this usercontrol in a form i should be able to drag controls in to the second panel which is by default visible and all the controls should act as child controls to the user control. I mean when ever we drag the user control they should move along with it..
for that this is the code i have written
partial class tool
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.panel2 = new System.Windows.Forms.Panel();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.SandyBrown;
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.button1);
this.panel1.Controls.Add(this.label1);
this.panel1.Location = new System.Drawing.Point(14, 13);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 40);
this.panel1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(136, 5);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(23, 23);
this.button1.TabIndex = 3;
this.button1.Text = "1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(20, 10);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(29, 13);
this.label1.TabIndex = 2;
this.label1.Text = "label";
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.Peru;
this.panel2.Location = new System.Drawing.Point(14, 47);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(200, 115);
this.panel2.TabIndex = 1;
//
// UserControl1
//
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(221, 172);
this.Load += new System.EventHandler(this.tool_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private string labeltext;
private Color pnl1color;
private Color pnl2color;
public string Labeltext
{
get
{
return labeltext;
}
set
{
labeltext = value;
label1.Text = labeltext;
}
}
public Color Pnl1color
{
get
{
return pnl1color;
}
set
{
pnl1color = value;
panel1.BackColor = pnl1color;
}
}
public Color Pnl2color
{
get
{
return pnl2color;
}
set
{
pnl2color = value;
panel2.BackColor = pnl2color;
}
}
}
and in .cs file i have written this code
namespace tool
{
[Designer(typeof(ParentControlDesigner))]
public partial class tool : UserControl
{
public tool()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
some code to make panel visible and invisible
}
private void tool_Load(object sender, EventArgs e)
{
panel2.Visible = true;
label1.Text = "enter name of panel";
}
Thats it thats what i did. and when i tried to add controls to the second panel during design time i am not able to do that....
thanks for ur support.....
|
|
|
|
|
I have solved your problem!!!!
I am just going to try to find some references before I post the code, in case you are unable to understand my explanation.
Don't go away.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for the reply and kind approach.
|
|
|
|
|
Before I post the code, I would like to give you a couple of pointers about the code you posted.
1) the namespace. Do try not to use the same name for your namespace as you do for your class. This can sometimes confuse Visual Studio IDE
and generally cause delays that you don't need, and you have to write stuff like 'tool.tool.whatever', which just looks ugly . For example, if the code you posted is in the same project as your main form, have the namespace as something like toolTestApp, if it is a separate project have the namespace something like toolLibrary.
2) Where you have put your code. Just from the way the code was posted it looks as if this:
private string labeltext;
private Color pnl1color;
private Color pnl2color;
public string Labeltext
{
get
{
return labeltext;
}
set
{
labeltext = value;
label1.Text = labeltext;
}
}
public Color Pnl1color
{
get
{
return pnl1color;
}
set
{
pnl1color = value;
panel1.BackColor = pnl1color;
}
}
public Color Pnl2color
{
get
{
return pnl2color;
}
set
{
pnl2color = value;
panel2.BackColor = pnl2color;
}
}
is in the 'tool.Designer.cs' file. Bad Idea! The IDE is continually rewriting this file, your stuff could get deleted/overwritten, it probably won't at the moment but Microsoft could change the way that it creates the file so that it totally deletes the original first. Don't take the chance, move all that stuff to the 'tool.cs' file.
OK now the good bit.
The first thing to do is to create your own Designer to use instead of ParentControlDesigner . You will need what ParentControlDesigner does, so inherit from that. Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms.Design;
namespace toolLibrary
{
public class toolDesigner : ParentControlDesigner
{
public override void Initialize(System.ComponentModel.IComponent component)
{
base.Initialize(component);
if (this.Control is tool)
{
this.EnableDesignMode(((tool)this.Control).ControlPanel, "ControlPanel");
}
}
}
}
Now the changes to your code. There aren't many, and I've tried to highlight them all, but read it very carefully in case I missed any.
I'm only posting the main file as the only changes I made to the 'tool.Designer.cs' file was to move the stuff I talked about earlier.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace toolLibrary
{
[Designer(typeof(toolDesigner))]
public partial class tool : UserControl
{
public tool()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void tool_Load(object sender, EventArgs e)
{
panel2.Visible = true;
label1.Text = "enter name of panel";
}
public string Labeltext
{
get
{
return this.label1.Text;
}
set
{
label1.Text = value;
}
}
public System.Drawing.Color Pnl1color
{
get
{
return this.panel1.BackColor;
}
set
{
panel1.BackColor = value;
}
}
public System.Drawing.Color Pnl2color
{
get
{
return panel2.BackColor;
}
set
{
panel2.BackColor = value;
}
}
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
]
public Panel ControlPanel
{
get
{
return this.panel2;
}
}
}
}
Well, that's it. Give it a try. If it doesn't work, or you don't understand anything, please come back.
I couldn't find any decent references except for MSDN and you know where that is don't you.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
modified on Tuesday, June 30, 2009 2:14 PM
|
|
|
|
|
Kudos....Sir Henry.
Why can't we have a privilege to have a decent blog post or an article?
|
|
|
|
|
I started an article almost before I had finished the post.
I have to say that I am more excited about finding this, than anything I have coded for ages. Tehe tehe tehe.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry,
I couldn't wait to try out your code today ! This is an area I'm actively studying and frankly have not found the MSDN examples on this very grokkable. The one book I have on hand that is very useful is Matthew McDonald's book on Pro WinForms and Controls 2.0, chapters 13, and 26, but that's dated now.
I think your solution provides an elegant way to construct usercontrols with container sub-components some of which can function as design-time containers, and others of which can't. Much better than the awkwardness of the idea I came up which would have required building such critters at design-time on a form by individually placing each element as a separate UserControl.
One very small suggestion : only setting the text in the Label at design-time will NOT allow design-time changes to persist at run-time; right now the Load event called at run-time will over-write any changes.
fyi : this is working fine in VS 2010 beta.
Since starting to work on this I've come across all kinds of programming sites where people are posting questions complaining that 'ControlDesigner doesn't show up : you would think MS would do somthing to automatically hook in the System.Design.dll when you declared your usage of the System.Windows.Forms.Design library (ha, ha, right, in the "ideal" world).
Again, thanks for the "lesson."
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
modified on Wednesday, July 1, 2009 5:37 AM
|
|
|
|
|
BillWoodruff wrote: The one book I have on hand that is very useful is Matthew McDonald's book on Pro WinForms and Controls 2.0, chapters 13, and 26, but that's dated now.
I have that book as well, very useful, as you say. I also have Windows Forms 2.0 Programming by Sells and Weinhardt which of course is also somewhat dated now.
BillWoodruff wrote: One very small suggestion : only setting the text in the Label at design-time will allow design-time changes to persist at run-time; right now the Load event called at run-time will over-write any changes.
As far as this is concerned, you are, of course, correct. However, the code I posted is really just the OPs with additions from me to enable the design time behaviour and I regret to say that apart from any glaring problems I didn't really read it closely.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Bravo Henry !
I'd vote for that response for "above and beyond" humanity points
Look forward to your article.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Thank you so much Henry Minute..
Its really working very good....
Once again thank you so much for solving my problem.....
|
|
|
|
|
I have one more doubt..
If at all i want to make the first panel also active at design time as the second panel,along with the controls already present on it(1st panel) ,i mean the button and label should be there. And the functionality of visible and invisible alternatively on clicking the button should work..
Is it possible for me to do so..
IF it is possible can u guide me how...
Thanks & regards
|
|
|
|
|
According to the MSDN documentation all you have to do is repeat the steps I showed you for your lower panel with the upper panel.
1) create a public property for it, with the DesignerSerializationVisibility attribute
2) in the designer copy the EnableDesignMode line in Initialize changing the Control references to those you made in 1)
As far as the controls within those controls are concerned, I have not yet got round to experimenting along those lines. You might be able to repeat the two steps above for them as well, or you might have to change your panels into user controls deriving from Panel and give them their own designer which will use the EnableDesignMode stuff.
The thing is, I found out how to do it by experimenting and that is the best way to learn. Be brave, try things out. Start a new thread in the forum if you get half way and get stuck.
Good Luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
You need to add a reference to System.Design in your project. (use the 'References' context menu in Solution Explorer) you will then need using System.Windows.Forms.Design in your code file.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
THanks for your help..
I completed the work given for me successfully only because of your help...
Thank you...
Both the panels are editable for me now.....
|
|
|
|
|
My pleasure.
This time I learned something new as well, so it was good for both of us.
Good Luck with the rest of your work!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
You should post this as a new thread.
Hijacking another thread is considered rude.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Honey.rpk, D@nish, and Henry,
The roosters have been crowing loud since before 5am here, but nested UserControl hosting at design-time is not what's keeping me up, I assure you
Let me clear this up :
1. I'm using VS 2010 beta.
2. Creating a new Win Forms project in VS 2010 beta does not auto-include a reference to the System.Design dll which, I guess, the other .Design classes depend on. Was this also the case in VS 2008 ?
3. If you make sure you have a reference set to the System.Design dll, and you have declared :
using System.Design;
using System.Windows.Forms.Design;
you can use Henry's technique which is also shown in Matthew McDonald's aforementioned book on page 926.
4. If you don't have a reference in your project to System.Design.dll, you can still use the technique I included in C# which D@nish also pointed you to in an article doing the same thing in VB. I'm surprised this technique works without a reference to System.Design dll being set !
5. Nesting :
a. forget it : an instance of userControl #2 with ParentControlDesigner attribute placed inside userControl #1 with same attribute : followed by placing usercontrol #1 on a form at design-time ... after a build ... is NOT going to let the instance of UserControl #2 capture other controls.
b. if you can't forget it : there is a way (ugly, it is) :
1. build your separate usercontrols 1,2
2. adorn each of them with the ParentControlDesigner attribute
3. at design time on a Form :
a. place an instance of usercontrol #1 on the form
b. place an instance of usercontrol #2 on the form and drag it so is "captured" usercontrol #1
c. you will now find both usercontrols are capable of capturing controls.
d. disclaimer : not tested with derived controls inheriting from containers like Panel
Disclaimer : for all I know there are other more elegant methods to achieve such weirdness; but a good question is : "what design advantages come from such design-time nested usercontrols or derived controls ?"
If anything, I can see such "beasts" as a liability, but, who knows, maybe there is some scenario where such "critters" are just right for the zoo.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Here's my problem: The panel won't accept the other controls dropped on it.
At design time, if I drag the user control onto a Windows form, then drop other controls on the user control, the dropped controls become children of the Windows form, and not the user control. When I drop them, they disappear, but if I drag the user control out of the way, the other controls are on the Windows form, exactly where I dropped them.
I tried changing the user control's designer to the Parent Control Designer,like this:
-----------------------------------------------------------
using System.ComponentModel.Design;
....
[Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design",
typeof(IDesigner))]
public partial class FSGroupPanel : UserControl
{
...
}
-------------------------------------------------------------
That helped some, but not a lot. Now, when I drop another control on the
user control at design time, it still disappears. However, if I then drag the user control around on the Windows form, the other control appears in the user control during the drag, at the place where I dropped it. However, the dropped control disappears when I stop dragging the user control, and the dropped control doesn't appear at run time at all.
<b><u>Here is my question:::::::</u></b>
I want a solution to make the disappeared dropped control visible?
|
|
|
|
|
this is my source that i created
Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
FontDialog1.ShowDialog()
RichTextBox1.Font = FontDialog1.Font
End Sub
Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
ColorDialog1.ShowDialog()
RichTextBox1.ForeColor = ColorDialog1.Color
End Sub
---------------------------------
when i wanna change color and font in richtextbox,all of text in textbox is changed.how to make
source code that change color and font in text that we highlight
bah10z
bah10z
|
|
|
|
|
Hi,
a RichTextBox has a lot of properties whose names start with "Selection", those operate on the currently selected content. Read the MSDN documentation for all the details.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
In brief,We have to make a custom control which consists of the following features:
1.On button click,one of the panels should be minimized.
2.The custom properties should be changed.
3.Other controls that are dragged on to this custom control should move along with that custom control.
4.The other controls placed below this custom control should shift upwards and downwards along with the maximize and minimize of the custom control.
In the above features,we got succeeded in developing the custom control with the first two properties but we are facing some problems in case of next two even we tried to write an event.
So,plz help me in solving this.
|
|
|
|
|
Handle the Drag events for the panel to place controls in it. Anchor and dock them properly to panel.
Show what you tried and tell where are you stuck. No one here is going to write code for you, atleast not for free.
|
|
|
|
|
I want to remove driver named "SAA7134 driver" by the way of using "devcon" command,how to do?
the dirver list as follow:
Inter(r) 82801BA/BAM AC'97 Audio Controller
SAA7134 driver
SAA7134 driver
SAA7134 driver
SAA7134 driver
|
|
|
|
|