.net miner

something about life, me and .net
  • Home
  • Categories
    • C#
    • .Net
    • Tools
    • General
    • Visual Studio
    • Open Source Projects
  • Contact Me
.Net•C#•General•Visual Studio

How To Permit Multiple Selections For Enum Properties

28 August 2008 by Ozcan Degirmenci No Comments
Enum - Flags Editor Example Interface Image

An example screenshot of the Flags Editor

PropertyGrid will use default editor for the properties which’s type is enum. This default editor does not allow multiple selections even the Enum has Flags attribute.

I have been prepared a new Editor for this kind of properties.

Our editor’s code is as follows;

internal class FlagsEditor : UITypeEditor
{
   FlagsEditorControl editor = null;
   public FlagsEditor()
   { }
    
   // our editor is a Drop-down editor
   public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
   {
      return UITypeEditorEditStyle.DropDown;
   } 
  
   public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
   {
       // if value is not an enum than we can not edit it
      if  (!(value is Enum))
         throw new Exception("Value doesn't support");
     
      // try to figure out that is this a Flags enum or not ?
      Type enumType = value.GetType();
      object[] attributes =  enumType.GetCustomAttributes(typeof(FlagsAttribute), true);
      if (attributes.Length == 0)
         throw new Exception("Editing enum hasn't got Flags attribute");
      // check the underlying type
      Type type = Enum.GetUnderlyingType(value.GetType());
      if (type != typeof(byte) && type != typeof(sbyte)  && 
            type != typeof(short) && type != typeof(ushort) && 
           type != typeof(int)&& type != typeof(uint))
        return value;
      if (provider != null)
      {
         // use windows forms editor service to show drop down
         IWindowsFormsEditorService edSvc = provider.GetService( 
              typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
         if (edSvc == null)
             return value;
         if (editor == null)
             editor = new FlagsEditorControl(this);
         // prepare list
         editor.Begin(edSvc, value);
         // show drop down now
         edSvc.DropDownControl(editor);
         // now we take the result
         value = editor.Value;
         // reset editor
         editor.End();
      }
      return Convert.ChangeType(value, type);
   }
}

In this code FlagsEditorControl is a UserControl which PropertyGrid hosts it in a drop down during the edit operation.
You can change your design by changing this Control.

To use this editor for a property, we have to write Editor Attribute to that property as the below;

// set editor of this property to our FlagsEditor
[Editor(typeof(FlagsEditor), typeof(UITypeEditor))]
public FileAttributes FlagsAttribute
{
       get { return _FlagsAttribute; }
       set { _FlagsAttribute = value; }
}
Share:
Reading time: 1 min
.Net•C#•General

What Is The NET Problem With EnableWindow

26 August 2008 by Ozcan Degirmenci No Comments

EnableWindow function enables or disables the mouse and keyboard input to the specified control. You can use this function from user32.dll as the follows;

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool EnableWindow(HandleRef hWnd, bool enable);
  
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool EnableWindow(IntPtr hWnd, boolenable);

Continue reading

Share:
Reading time: 2 min
.Net•C#•General•Visual Studio

CollectionEditor Something About

25 August 2008 by Ozcan Degirmenci No Comments

Today I wrote a simple example which shows how we can use CollectionEditor of the .NET. In addition to this I also made a simple example which shows how to implement custom CollectionEditor which allows us to add more than one item to the collection.

Something About CollectionEditor

An example screenshot of the Collection Editor

Continue reading
Share:
Reading time: 1 min
.Net•C#•Tools•Visual Studio

Extending PropertyGrid Adding custom PropertyTab and PropertyDescritors

24 August 2008 by Ozcan Degirmenci No Comments
Extending PropertyGrid Adding custom PropertyTab and PropertyDescritors

An example screenshot of the Custom Property Grid Tab

Most of the programmers who uses Visual Studio .NET knows PropertyGrid which is the main control in the Properties Window of the Visual Studio.

Continue reading
Share:
Reading time: 1 min
.Net•C#•Visual Studio

How To Make Multilanguage Supported Category And Description Attributes

21 August 2008 by Ozcan Degirmenci No Comments

If you have written any .NET components you must be familiar with Category and Description attributes. We use Category attribute to identify the property’s category and Description attribute is for the short description of that property. But because of the nature of Attributes in .NET we cannot pass any parameter to these attributes for Multilanguage support.

[Category(Properties.Resources.MyCategory)]
[Description(Properties.Resources.MyDescription)]
public int MyProperty { … }

This kind of usage is not allowed for .NET, because we are only allowed to give constant values to the attributes constructor.  So how can we use these attributes as Multilanguage?

Continue reading
Share:
Reading time: 1 min
.Net•C#•General•Tools•Visual Studio

How To Create TFS WorkItems Programmatically

by Ozcan Degirmenci No Comments

If you are using Team Foundation Server with Visual Studio, it will be useful for you to integrate your projects bug system with the TFS Work Items system. You can write a simple module for your program which will handles the exceptions and collects needed information and send them to the TFS.

So how can we do something like that? First you have to write an error management module which will handles exceptions, errors, etc. and generates understandable information from them. After generating this information lastly you have to send this information to the TFS.

Continue reading

Share:
Reading time: 3 min

Search

Projects

  • Process Viewer
  • B-Msn
  • Runtime Member Proxies
  • Searchable RichTextBox

Categories

  • .Net (19)
  • C# (12)
  • General (13)
  • Open Source Projects (4)
  • Quantum (1)
  • Tools (9)
  • Visual Studio (6)

Archives

  • November 2018
  • September 2018
  • September 2010
  • August 2010
  • August 2009
  • September 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • February 2008
  • January 2008

About me

Hi, my name is Ozcan Degirmenci. I'm co-founder and CEO at Crs Soft.

Tags

Assembly Collection Editor Dialog Support Dynamic method enum Flag Editor Loader Exceptions Ole Calls Open source project open source projects Perfornance Comparison process viewer Proxy quantum Reflection Run Apps From Web schrödinger's cat Searchable Richtextbox Spoon thought experiment thread

© 2018 copyright ÖZCAN DEĞİRMENCİ // All rights reserved.