|
The problem is that the Type of the property warrants an editor, so you need to attribute your property (which takes precedence over the attribute on the property Type) with an editor that doesn't do anything:
using System;
using System.Drawing;
using System.Drawing.Design;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PropertyGrid propertyGrid1;
private System.Windows.Forms.RadioButton radioButton1;
private CustomRadioButton radioButton2;
private System.Windows.Forms.GroupBox groupBox1;
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new CustomRadioButton();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
this.propertyGrid1.CommandsVisibleIfAvailable = true;
this.propertyGrid1.LargeButtons = false;
this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar;
this.propertyGrid1.Location = new System.Drawing.Point(8, 88);
this.propertyGrid1.Name = "propertyGrid1";
this.propertyGrid1.SelectedObject = this.radioButton1;
this.propertyGrid1.Size = new System.Drawing.Size(280, 264);
this.propertyGrid1.TabIndex = 0;
this.propertyGrid1.Text = "propertyGrid1";
this.propertyGrid1.ViewBackColor = System.Drawing.SystemColors.Window;
this.propertyGrid1.ViewForeColor = System.Drawing.SystemColors.WindowText;
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(8, 16);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(160, 24);
this.radioButton1.TabIndex = 1;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "BackgroundImage ...";
this.radioButton1.CheckedChanged += new System.EventHandler(this.switchObject);
this.radioButton2.Location = new System.Drawing.Point(8, 40);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(160, 24);
this.radioButton2.TabIndex = 2;
this.radioButton2.Text = "No BackgroundImage ...";
this.radioButton2.CheckedChanged += new System.EventHandler(this.switchObject);
this.groupBox1.Controls.Add(this.radioButton1);
this.groupBox1.Controls.Add(this.radioButton2);
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(280, 72);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(296, 365);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.propertyGrid1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "Example";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void switchObject(object sender, System.EventArgs e)
{
RadioButton radio = sender as RadioButton;
if (radio != null && radio.Checked) this.propertyGrid1.SelectedObject = radio;
}
}
class CustomRadioButton : RadioButton
{
[Editor(typeof(CustomRadioButtonImageEditor), typeof(UITypeEditor))]
public override Image BackgroundImage
{
get
{
return base.BackgroundImage;
}
set
{
base.BackgroundImage = value;
}
}
class CustomRadioButtonImageEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.None;
}
}
} Pay attention to the BackgroundImage property in the PropertyGrid when selecting the different options.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
yup. that is what I am looking for. Why didnt I thinking that before? everything works great until huge problem appears are using collection. I got a whole list working in the property grid with collection,PropertyDescriptor,CollectionBase, and ICustomTypeDescriptor, but guess what?? that ... button is back again. I tried to use
class CustomListPropertyEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.None;
}
}
and went crashed bec collection was suspended bec of UITypeEditorEditStyle.None; other words, they wont make a list. so my question is: how can I get working with whole list without appear that frigging ... button on that list(if yu dont know what it is,then look my previous question.)?
If you dont know how to solve this problem, dont worry bout it.
|
|
|
|
|
GoodQuestion wrote:
If you dont know how to solve this problem, dont worry bout it.
Apparently you haven't noticed who I work for. I'm also a former C# Most Valuable Professional for Microsoft. This problems not at all hard...
...except that I'm afraid I don't understand you (grammatically). What I told you works for any property Type and you don't need to implement ICustomTypeDescriptor to implement it.
Are you saying that you're trying to assign a collection object to PropertyGrid.SelectedObject and you're getting the [...] button? That certainly doesn't make any since your object is the collection, unless your objects that you're collecting contains list or collection properties.
Please try to do a better job of explaining your situation. Also keep in mind that if you got this to work for an IList implementation than it would work for an <cod>ICollection as well (IList inherits from ICollection ). The key is to remember that attributed properties takes precedence over attribute types, so the PropertyGrid will use the EditorAttribute on your property (if any) before using the EditorAttribute on the property's type. This is documented in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Sorry bout poor explaining abut my situation bec I was really hurried that I have an appointment. Before I starting to ask you, I want to say thanks that you replied quickly and helpful to me. I have plenty time to explaining what is my situation. I am trying to rid .. or modal on property grid. I had success with using UITypeEditorEditStyle.None on other propertygrid but I cant get this one. I made picture(it is not pretty bec I cant copy Paint Microsoft on this message board) to show where is mistake and I put ***** and it will help you to find where are they. This is part of source codes with property grid. I know it is big one bec it is easier to show you then explain everything, you know.
(CMainViewDlg)
try
{
ArrayList OpnShapeList = m_ArrayList;
CPartInfo partInfo = new CPartInfo();
partInfo.Job = m_Part.JobName;
............
SurfaceInfo empsurf = new SurfaceInfo();
int nCount = 1;
foreach(ILogicalOperationShape pIOpnShape in OpnShapeList)
{
string[] strHeaderArray = null;
...
empsurf = new SurfaceInfo();
empsurf.Pattern = "Barber" + nCount;
empsurf.OpnShapeData = pIOpnShape.OpnShapeName;
.....
for(int i=0; i < strHeaderArray.Length; i++)
{
string strValue;
....
if(i == 3)
empsurf.InnerDia = strValue;
if(i == 4)
empsurf.Bolt_Dia = strValue;
if(i == 5)
empsurf.NumberofBolt = strValue;
}
partInfo.Surfaces.Add(empsurf);
nCount++;
}
propertyGridPart.SelectedObject = partInfo;
(partinfo)
public class CPartInfo : UITypeEditor
{
private string m_strJob = "";
.....
SurfaceCollection surfaces = new SurfaceCollection();
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.None;//it is not working
}
[CategoryAttribute("Part Data"), DescriptionAttribute("Job Name"),ReadOnly(true)]
public string Job
{
get
{
return m_strJob;
}
set
{
m_strJob = value;
}
}
...........
..........
[TypeConverter(typeof(SurfaceCollectionConverter)),CategoryAttribute("Barbers")]// make list from SurfaceCollection
public SurfaceCollection Surfaces
{
get
{
return surfaces;
}
set
{
surfaces = value;
}
}
(SurfaceCollection)
public class SurfaceCollection : CollectionBase, ICustomTypeDescriptor
{
#region COLLECTION
public void Add( SurfaceInfo emp )
{
this.List.Add( emp );
}
public void Remove( SurfaceInfo emp )
{
this.List.Remove( emp );
}
public SurfaceInfo this[ int index ]
{
get
{
return (SurfaceInfo)this.List[index];
}
}
........(all are ICUSTOMTYPEDESCRIPTOR)
public PropertyDescriptorCollection GetProperties()
{
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list of employees
for( int i=0; i
|
|
|
|
|
Implementing UITypeEditor won't do it like you are for the CPartInfo class. You can implement it, but you need to attribute CPartInfo using the EditorAttribute like in the example I gave you before:
[Editor(typeof(CParkInfo))]
public class CPartInfo : UITypeEditor
{
} Honestly, though, you should extend this with some other class than CPartInfo since that limits your ability to derive from anything else now (since managed languages like C# - among many other non-.NET languages - don't support multiple inheritance).
Also, you shouldn't prefix your classes with "C". Hungarian notation in .NET is dead. You should read Naming Guidelines[^] in the .NET Framework SDK. Using consistent naming conventions helps poductivity, something the .NET Framework aims to accomplish and, IMO, does a very good job.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hello,
I want to formate my laptop, does anybody know how i can save my stored procedure and the sql database of a web project of mine??
thx
regards
patrick
|
|
|
|
|
Use a back up utility.
If it is just the database and nothing else you can go into Enterprise Manager, right-click the database, select All Tasks and then Backup Database...
Make sure you do a complete backup.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Hello,
thank you for your reply, but when i want to click ok in the backup db procedure to backup the database the following error occurs:
The volume on device 'C:\6.Semester\BackupShop' is not part of a multiple media set. BACKUP WITH FORMAT can be used to form a new set. BACKUP DATABASE is terminating abnormally.
Any ideas what went wrong??
thx
regards
|
|
|
|
|
Hello,
When i now want to open a Web Service in my VS.NET the following error occurs:
The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/ReservationClient'. 'HTTP/1.1 500 Server Error'.
Can anybody give me further help??
regards
patrck
|
|
|
|
|
pat270881 wrote:
Can anybody give me further help??
No further help can be given for something as unspecific as "Server Error". We need to know more information. If you can, browse to http://localhost/trace.axd. If it doesn't exist, turn on logging in /Web.config. If tracing isn't enabled and you're browsing to localhost, then the page handler for trace.axd should also tell you how to enable it.
Once that's done and you've reproduced the error, what exception are you getting? What does the exception text say?
Once you find all that out, post it to the ASP.NET forum. This forum is for C# questions not specific to ASP.NET since there's already a forum specific to ASP.NET.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
There were never display the Trace.axd when quoted it in the browser although i have trace enabled to true..???
in the event log of windows eventviewer the following warning occurs:
the server could not load the applicaiton '/LM/W3SVC'. 'Quoted Medadata could not be found.'
any ideas?
regards
patrick
|
|
|
|
|
ASP.NET forum
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
i'm creating a tool that requires constant detailed, fancy, colorful logging. The richTextBox provides pretty much most of what I need, but i find it unreliable. When text is being sent to the RTB constantly, attempting to color code each of the lines, it will miss some of them. and in some cases, when text becomes very large, it starts throwing exceptions when things like color coding are used.
so is richtextbox all i got when it comes to trying to do a lot of text logging, with different colors, fonts, etc?
i thought about replacing the rtb with a webbrowser control, and do everything in html, but then i thought how would i do this. i coudl have to recreate the entire page every time i made a change and refresh the browser, right? is there a way to just "add" text to an existing page through the webbrowser control?
thanks
|
|
|
|
|
Hi,
I am searching for the best regex mail pattern with C#.
Thank you,
Cem Louis
|
|
|
|
|
<br />
private Regex emailReg = new Regex(<br />
@"(?<Username>\w[-.\w]*)@(?<Host>[-a-z0-9]+(\.[-a-z0-9]+)*\." +<br />
@"(com|edu|gov|int|mil|net|org|biz|info|name|museum|coop|aero|[a-z][a-z]))",<br />
RegexOptions.IgnoreCase);<br />
Credit goes to http://www.bookpool.com/.x/ocstn6vf4n/sm/0596002890[^]
|
|
|
|
|
I don't recommend hard-coding the TLD (top-level domains). Change that to ([a-z]{1,}) instead and let DNS do its job.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Following that logic, you wouldn't need a Regex at all. Just try to send the email, using any random string as the address, and "let DNS do its job". ([a-z]{1,}) validates lots of invalid email addresses. The last time I checked, only the TLD's, plus 2 letter combinations were valid. Its best to spell this out explicitly in the regex.
|
|
|
|
|
|
So, by your token it's good to hard-code that which changes often. What leppie said is right, and at the very least if you're going to hard-code these values read them from a .config file instead (like from <appSettings> or your own configuration section.
Should one honestly have to fix, recompile, and re-deploy the assemblies that use this each time a new TLD is added?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I agree with you, that hard-coding those vales could make it hard to maintain and update the application. Depending on the intended use, there are always tradeoffs. Read from a config file, hard-code them, use your ([a-z]{1,}) method, and probably a few others. The goal of my original post was to give a good starting point for an email regex, and I considered the example from Jeffrey Friedl's book to be pretty good. Thank you for pointing out ways in which it could be improved in practice.
|
|
|
|
|
is there any way to combine my application with MS Equation Editor.
I just tried to give reference to MS Office 10.0 object library to use the equation editor as a com object which inside the Word.but I am failed.
I am lookng for a way to use it in my application. Any tutorials any articles that you can suggest,that it will be helpfull for me.
(visual C# windows application)
Thanks...
|
|
|
|
|
I'm not sure if what I'm wanting to do is possible in C# or not, but I thought I'd pose the question. In C++, we are able to create ActiveX controls and host them in a generic container. The container can read a menu system from a database and populate a tree and have an assigned GUID for the object to construct when each tree node is clicked. Can this phisophy be done in a Windows form .NET application (without ActiveX)? Can I construct a Form or a UserControl by simply reading in the form class name from a database table? I know I can create a builder class that could return a new object for a given piece of text, but that would mean I would have to update this builder class each time a new form were developed. I would like to create a container that never had to be modified...not sure if that is possible.
Ron Ward
|
|
|
|
|
|
Thank you Nick! This is exactly what I needed. I had heard the Reflection term thrown around, but never realized what it was. Being a Visual C++ developer, this term means something very different to me. Thank you again.
|
|
|
|
|
What I am trying to do is to first start a form, which gives the user a choice between starting the application as a server or as a client. When the user has made this choice, the form should terminate. Now I wish to start another form, which provides another user interface. Like this:
static void Main()
{
ServerOrClientForm serverOrClient = new ServerOrClientForm();
Application.Run(serverOrClient);
serverOrClient.InputSelection();
UserInterface ui = new UserInterface();
Application.Run(ui);
// pass information to and from ui
obj = ui.GetInfo();
// ...
ui.SetInfo(obj);
}
The first form works well, but the other one (ui) does not show up at all. What am I doing wrong?
|
|
|
|