473,386 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

displaying bitflags as enumerated text and not int

Hi

i am trying to make a small mdoification to and exisiting dll control,
in its source code.

Im trying to expose one of its internal properties so the user can set
it in the ide at designtime, but the property consists of enumerated
constants used in bit operations, and when the values are exposed they
show up as integers instead of the text contstants listed
EG

//Initial value
private int dwFlags = Gdi.PFD_DRAW_TO_WINDOW |
Gdi.PFD_SUPPORT_OPENGL | Gdi.PFD_DOUBLEBUFFER;

// I expose the property to the ide user here
#region DWFlags
/// <summary>
/// sets the OpenGL control's Flag properties.
/// </summary>
[Category("OpenGL Properties"), Description("Flag
properties.")]
public String DWFlags {
get {
return dwFlags);
}
set {
dwFlags = value);
}
}
#endregion DWFlags
When you see it in the ide the DWFlags value shows as 37, but i want
it to show as
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;

in the control field.

I also want the user to be able to enter the flags as the above text,
even adding more flags to also be used in this bit operation and have
it translated or sent to the control in form that it can be used.

the flags are used in the following opengl structure

Gdi.PIXELFORMATDESCRIPTOR pfd = new Gdi.PIXELFORMATDESCRIPTOR();// The
pixel format descriptor
pfd.nSize = (short) Marshal.SizeOf(pfd);
// Size of the pixel format descriptor
pfd.nVersion = 1;
// Version number (always 1)
--------------->>>i want to replace this line bellow

pfd.dwFlags =Gdi.PFD_DRAW_TO_WINDOW |
Gdi.PFD_SUPPORT_OPENGL | Gdi.PFD_DOUBLEBUFFER;

----------------------------->>> with pfd.dwFlags = dwFlags;

pfd.iPixelType = (byte) Gdi.PFD_TYPE_RGBA;
etc etc etc etc
You can see the flags are enumerated constants from opengl
Can anyone help please on how i can pass these flag data beckwards and
forwards to the control and have the user edit it, and still have it
come back and be usuable in the structure
thanks for any help

Peted
Sep 20 '07 #1
4 1610
OK, you have an odd combination of int, string (so that your posted
code doesn't compile), and what perhaps could be an enum. Realistic
code would help people give a realistic answer!

However; *assuming* that Gdi doesn't declare a suitable enum, I would
simply do it myself; the following does most of what you want. If you
want a check-box style value-editor, then you'll need to add a custom
[Editor]; I'm pretty certain you could pick up a popup (or pop-down)
check-box style editor easily enough (it would take about 10 minutes
to write one from scratch).

If you don't want to go down the enum route, then you'd need to write
a TypeConverter, and specify this against the property; then you can
handle the parsing and formatting yourself - but I'd recommend using
enum!

Of course, if the "Gdi" class is declared in your project, then simply
define the enum values directly. Note that you can cast directly from
enum to/from int to get the int value to pass to whatever needs it.

using System;
using System.ComponentModel;
using System.Windows.Forms;
static class Program {
static void Main() {
Application.EnableVisualStyles();
using(Form form = new Form())
using (PropertyGrid grid = new PropertyGrid()) {
grid.Dock = DockStyle.Fill;
grid.SelectedObject = new SomeClass();
form.Controls.Add(grid);
Application.Run(form);
}
}
}
[Flags]
enum GdiDwFlags {
None = 0,
DrawToWindow = Gdi.PFD_DRAW_TO_WINDOW,
SupportOpenGl = Gdi.PFD_SUPPORT_OPENGL,
DoubleBuffer = Gdi.PFD_DOUBLEBUFFER
}
static class Gdi { // I'm making up the values... presumably defined
externally
public const int PFD_DRAW_TO_WINDOW = 1, PFD_SUPPORT_OPENGL = 2,
PFD_DOUBLEBUFFER = 4;
}
class SomeClass {
private GdiDwFlags dwFlags = GdiDwFlags.DrawToWindow |
GdiDwFlags.SupportOpenGl | GdiDwFlags.DoubleBuffer;
[Category("OpenGL Properties"), Description("Flag properties.")]
public GdiDwFlags DWFlags {
get {return dwFlags;}
set {dwFlags = value;}
}
}
Sep 21 '07 #2
Hi Marc

thankyou for your effort, i apollogies my description of what i was
after was realy bad.

I will repost my question with a better explanation

Peted

Sep 21 '07 #3
especially in the adding of events to the button click

b.Click += delegate { OnValueSelected(); };

This is an anonymous method; it is equivalent to having:
public void OKButtonClicked(object sender, EventArgs args) {
OnValueSelected(); // raise the ValueSelected event
}
and using
b.Click += new EventHandler(OKButtonClicked);

Basically, it just saves me some typing, which I consider a good thing.

Sep 23 '07 #4
thanks heaps

Peted
On Sun, 23 Sep 2007 02:07:14 -0700, Marc Gravell
<ma**********@gmail.comwrote:
>especially in the adding of events to the button click

b.Click += delegate { OnValueSelected(); };

This is an anonymous method; it is equivalent to having:
public void OKButtonClicked(object sender, EventArgs args) {
OnValueSelected(); // raise the ValueSelected event
}
and using
b.Click += new EventHandler(OKButtonClicked);

Basically, it just saves me some typing, which I consider a good thing.
Sep 25 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: mplogue | last post by:
I have a form (frmMain) with a subform (frmSub), each with enumerated fields of the same name (txt1, txt2, etc). I'm trying to make a function that will take the values for each field in frmMain,...
0
by: Martin | last post by:
I am currently writing a program and I am trying to create a property for a custom control that can be set a value of either 'linear' or 'traditional' in the properties window in design time from an...
3
by: Matthias S. | last post by:
Hi, I've got a class with an Options property. I'd like to implement this property in a way that a calling syntax like MyClassInstance.Options = MyClass.Option1 | MyClass.Option2; can be...
0
by: Brandon | last post by:
Hello all, and thanks for taking a look at this. First off, the project I am working on is a server/client application that contains a shared assembly of common classes between the two...
8
by: Vince Varallo | last post by:
Hello All, I would like to display all logged on users on a web page. I store each user's name in a session varible, but I don't seem to be able to loop through a sessions collection to view...
4
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state...
7
by: John Goche | last post by:
Hello, The following program compiler and runs fine under gcc and produces the output 3. However, I am not sure whether such behavior is legal. In particular, as a related question, how would I...
1
by: senfo | last post by:
I'm using an enumerated type to identify a record type that relates to a unique ID in a database. Identity columns in SQL start at 1, while enumerated types in C# start at 0. I didn't think it...
4
by: Rex the Strange | last post by:
Hello all, Can anyone please tell me why I can't do this (and what I can do to get the equivalent effect): In the code: public enum myenum value1 value2
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.