473,548 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_DOUBLEB UFFER;

// I expose the property to the ide user here
#region DWFlags
/// <summary>
/// sets the OpenGL control's Flag properties.
/// </summary>
[Category("OpenG L Properties"), Description("Fl ag
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_WIN DOW | PFD_SUPPORT_OPE NGL | PFD_DOUBLEBUFFE R;

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.PIXELFORMAT DESCRIPTOR pfd = new Gdi.PIXELFORMAT DESCRIPTOR();// 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_T O_WINDOW |
Gdi.PFD_SUPPORT _OPENGL | Gdi.PFD_DOUBLEB UFFER;

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

pfd.iPixelType = (byte) Gdi.PFD_TYPE_RG BA;
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 1618
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.Componen tModel;
using System.Windows. Forms;
static class Program {
static void Main() {
Application.Ena bleVisualStyles ();
using(Form form = new Form())
using (PropertyGrid grid = new PropertyGrid()) {
grid.Dock = DockStyle.Fill;
grid.SelectedOb ject = new SomeClass();
form.Controls.A dd(grid);
Application.Run (form);
}
}
}
[Flags]
enum GdiDwFlags {
None = 0,
DrawToWindow = Gdi.PFD_DRAW_TO _WINDOW,
SupportOpenGl = Gdi.PFD_SUPPORT _OPENGL,
DoubleBuffer = Gdi.PFD_DOUBLEB UFFER
}
static class Gdi { // I'm making up the values... presumably defined
externally
public const int PFD_DRAW_TO_WIN DOW = 1, PFD_SUPPORT_OPE NGL = 2,
PFD_DOUBLEBUFFE R = 4;
}
class SomeClass {
private GdiDwFlags dwFlags = GdiDwFlags.Draw ToWindow |
GdiDwFlags.Supp ortOpenGl | GdiDwFlags.Doub leBuffer;
[Category("OpenG L Properties"), Description("Fl ag 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(OK ButtonClicked);

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**********@g mail.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(OK ButtonClicked);

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
1842
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, and put them in the same-named field in the subform. Here's the function: '--------Start Code-------- Function cmdFillSub() Dim i As Integer
0
1387
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 enumerated type storing 1 or 0 but I just can't seem to get it to work. Any ideas anyone out there. Thanks Martin
3
4885
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 used. My questions with that: 1. How do I store these BitFlags internally?
0
1071
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 components. One of these shared items is a bunch of commonly used types. These included hard-coded paths, extension types, and some common enumerated...
8
1850
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 all sessions. Has anyone else figured this out? Thanks in advance, Vince
4
4372
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 machines in C# where the machine can use the enumerated 'state' to execute (thus the term 'machine' as in 'state machine') the machine operations as...
7
2610
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 go about checking that a supplied integer is contained within the set of values of an enumeration? Is there a way to do this? Thanks,
1
1603
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 would be a big deal because I could just force the values of the enum to start at 1. Database: ID RecordType -- ---------- 1 TypeA
4
2979
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
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7711
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7954
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3497
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
755
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.