|
In any case, I am sure you don't believe me. So here is a code made for you. Run it and you will see it.
public class Form2 : Form
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.item1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.item1ToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.item2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.item3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.item4ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.subItem1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.subItem2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.item1ToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(491, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
this.item1ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.item1ToolStripMenuItem1,
this.item2ToolStripMenuItem,
this.item3ToolStripMenuItem,
this.item4ToolStripMenuItem});
this.item1ToolStripMenuItem.Name = "item1ToolStripMenuItem";
this.item1ToolStripMenuItem.Size = new System.Drawing.Size(77, 20);
this.item1ToolStripMenuItem.Text = "MainMenu";
this.item1ToolStripMenuItem.MouseMove += new System.Windows.Forms.MouseEventHandler(this.item1ToolStripMenuItem_MouseMove);
this.item1ToolStripMenuItem1.Name = "item1ToolStripMenuItem1";
this.item1ToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
this.item1ToolStripMenuItem1.Text = "Item 1";
this.item2ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.subItem1ToolStripMenuItem,
this.subItem2ToolStripMenuItem});
this.item2ToolStripMenuItem.Name = "item2ToolStripMenuItem";
this.item2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.item2ToolStripMenuItem.Text = "Item 2";
this.item3ToolStripMenuItem.Name = "item3ToolStripMenuItem";
this.item3ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.item3ToolStripMenuItem.Text = "Item 3";
this.item4ToolStripMenuItem.Name = "item4ToolStripMenuItem";
this.item4ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.item4ToolStripMenuItem.Text = "Item 4";
this.subItem1ToolStripMenuItem.Name = "subItem1ToolStripMenuItem";
this.subItem1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.subItem1ToolStripMenuItem.Text = "SubItem1";
this.subItem2ToolStripMenuItem.Name = "subItem2ToolStripMenuItem";
this.subItem2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.subItem2ToolStripMenuItem.Text = "SubItem2";
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(491, 388);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form2";
this.Text = "Form2";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem item1ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem item1ToolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem item2ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem subItem1ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem subItem2ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem item3ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem item4ToolStripMenuItem;
public Form2()
{
InitializeComponent();
SetMenuDetails(item1ToolStripMenuItem);
}
private void SetMenuDetails(ToolStripMenuItem menu)
{
foreach (ToolStripMenuItem item in menu.DropDownItems)
{
UpdateItem(item);
}
}
private void UpdateItem(ToolStripMenuItem item)
{
foreach (ToolStripMenuItem subItem in item.DropDownItems)
{
UpdateItem(subItem);
}
item.MouseMove += new MouseEventHandler(item_MouseUp);
}
void item_MouseUp(object sender, MouseEventArgs e)
{
ToolStripMenuItem item = (ToolStripMenuItem)sender;
if (item.DropDownItems.Count > 0)
{
ToolStripMenuItem subItem = (ToolStripMenuItem)item.DropDownItems[0];
item.ShowDropDown();
Point location = subItem.Bounds.Location;
Cursor.Position = new Point(Cursor.Position.X + location.X + item.Bounds.Width/2, Cursor.Position.Y + location.Y );
}
}
private void item1ToolStripMenuItem_MouseMove(object sender, MouseEventArgs e)
{
this.Text = e.Location.ToString();
}
}
|
|
|
|
|
I wanted to create a custom control property that includes checkboxes, just like ShortCutKeys property for ToolStripMenuItem. How would I create something like this?
thank you
|
|
|
|
|
Let me see if i get this right, you want to put some custom control into the ToolStrip or MenuStrip right ???
With great code, comes great complexity, so keep it simple stupid...
|
|
|
|
|
ok, sorry for not being more clear. No, I have a custom control. And for this control, I need to create a custom property that has checkboxes in my customs control's property grid. Similar to 'Dock' property that displays a clickable custom graphic on the dropdown. Or if you look at 'ShortCutKeys' property for 'ToolStripMenuItem' control, you'll see a drop down with checkboxes.
So lets say I have a custom Button control with custom 'Text' property. And when a user sets this 'Text' property, in the property grid dropdown for this property, I need to display checkboxes with values.
|
|
|
|
|
|
A good answer. It helps me to resolve my question.
|
|
|
|
|
Does any one know how much storage space a Type object requires? For example, an instance of a Type contains a multitude of properties. Are these properties stored in memory or retrieved when needed?
Also, does anyone know how fast the "is" function is evaluated? I've been using the "is" function a lot more frequently and I don't want to inadvertently be slowing down my code.
Example:
if (variable is ISomeInterface1)
{}
else if (variable is ISomeInterface2)
{}
else if (variable is ISomeInterface3)
{}
...
If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.
|
|
|
|
|
AFAIK there is no "Type" object - instead every object has a type, which defines what properties and methods the object has. As such, a "Type object" has no specific size - it depends on what kind of object it is!
As for the "how fast is "is ", why would it matter - how would your code work if you didn't check what type you are receiving, unless it is a single type of object? I.e. if your code is similar to a click event
void ClickIt(object sender, EventArgs e) then you have to use either
if (sender is MyClass)... or
MyClass mine = sender as MyClass in order to use the parameter.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
I assume he means if you do System.Type t = o.GetType() ; , how much space will be used.
Thinking of it that way... do you just get a reference to the class in the loaded assembly?
|
|
|
|
|
Dunno - but this is making my brain hurt! (I had forgotten about the System.Type class; I try to avoid using reflection if I can.)
What is he doing that makes the size of a Type important, I wonder?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
OriginalGriff wrote: What is he doing
Waiting for Friday?
|
|
|
|
|
Hi,
There is a Type class, with a constructor. And object.GetType() returns a Type instance. So there are type objects, and they all must have the same size; not sure how to get its value, I expect it to be small. Furthermore an experiment shows the type objects are unique, i.e. there is at most one for each class.
FWIW: one should use the is/as keywords to perform type tests, and most certainly not compare Type.ToString() with some string literal.
is and as translate to a simple IL instruction, and are assumed to be very fast.
PS: if you frequently need dispatching based on type, as in your example, how about using a virtual method/property?
|
|
|
|
|
Luc Pattyn wrote: how about using a virtual method/property?
Due to lack of covariance and contravariance? I think I was just butting my head up against that... again.
|
|
|
|
|
Hey Luc!
Your answer seems to be the most intelligent of the three responses. (Sorry guys)
I have a fairly advanced knowledge of the .Net Framework but there are certain things that Microsoft doesn't explain clearly. For a general developer, I'm sure most of this is unnecessary.
Luc Pattyn wrote: PS: if you frequently need dispatching based on type, as in your example, how about using a virtual method/property?
Cool idea, but I don't think it's my best option for this app.
Cheers!
Richard
If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.
|
|
|
|
|
Hi Richard,
Richard Blythe wrote: there are certain things that Microsoft doesn't explain clearly
you know, you might be right about that
|
|
|
|
|
Lol, thanks again for the response.
If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.
|
|
|
|
|
You're welcome.
|
|
|
|
|
Richard Blythe wrote: how much storage space a Type object requires
Assume the worst. If you use Reflection to get such information, it's best to cache what you need.
Richard Blythe wrote: how fast the "is" function is evaluated
You could do a bunch of them and time them.
If you do a lot of that you might be interested in my TypeTransmogrifier[^].
modified on Tuesday, March 30, 2010 3:10 PM
|
|
|
|
|
Hi..
I want to create a line, polygon shapefile.. Pls can someone help...
|
|
|
|
|
Draw a line from A to B.
Draw another line from B to C.
.. repeat ad nauseam to X ...
Draw a line from X to A.
Voila! A polygon.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
U didnt get me actually.
I am using map control. I got this control from the mapwinGIS.
On the mapcontrol i create vector and raster layers...
Vector layer is basically opening shapefiles.
Now i need to create point shapefile, line shapefile.
|
|
|
|
|
I think this site[^] will have the best information.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Hello everybody,
I am using map control to add shapefiles in my project.
I want to add image to the map control and also drag and resize it.
Pls can someone help me...
I am able to place the image on the map control. But not able to drag and resize.
|
|
|
|
|
How are you placing the image? Are you drawing it yourself, or using a PictureBox? How you drag and re-size will be affected.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
I'll have an image file say bitmap file. And am adding it as a lyer on the mapcontrol.. Now i need to edit it or like drag/move it from one position to another and resize it.
Am not using picturebox. Am using mapcontrol. and display my image on that mapcontrol only. u get the map control from mapwindowgis
|
|
|
|