|
Well, I try to use set and get to simulate the union. It seems work in my eye.
class A
{
public int a;
}
class B
{
public char b;
}
class union
{
object obj;
public A aa
{
get
{
return (A)obj;
}
set
{
obj=value;
}
}
public B bb
{
get
{
return (B)obj;
}
set
{
obj=value;
}
}
}
|
|
|
|
|
Can a component obtain a reference to its container object?
I'm writing a component that needs two pieces of information about its container:
1. Is the container a form?
2. If so, what is its window handle? (.Handle property)
The "Container" object only lets me access a very limited interface that doesn't do what I want.
--Thanatos
|
|
|
|
|
You should be able to test the Container object for what type it is, then once you know it is a specific type you can cast it to that type and access the property you want.
ie
if( Container is System.Windows.Form ) {<br />
System.Windows.Form containerForm = (Form) Container;<br />
}
HTH,
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
That sounded good, so I tried this test:
I built a simple component with this method:
public void ChangeParentColor()
{
if( Container is Form )
{
Form containerForm = (Form)Container;
containerForm.BackColor = Color.Aqua;
}
}
This built just fine. I placed this component on a new form, along with a button. When the button was clicked, this method fired:
private void buttonclick(object sender, System.EventArgs e)
{
containerTestComponent1.ChangeParentColor();
button1.Text="I was clicked";
}
This project also built just fine, but even though the caption of the button changes properly (demonstrating that the button event fired), the color of the form refused to change to aqua.
|
|
|
|
|
While i'm not going to offer any advice in the container issue... I just thought you might like to know that that code is not the best way to do what you are doing.
It's better* to do this:
Form containerForm = Container as Form;
if( containerForm != null ) {
// Use containerForm
}
*
"better" meaning that the produced IL is smaller and faster.
If you don't believe me, make a simple executable and examine the IL yourself.
The general rule-o-thumb is:
If you are going to do a cast directly after an "if-is" and use that casted object, use "as" instead.
If you just want to test the type and not do something with the object as that type, use "is".
|
|
|
|
|
Hmm...
I haven't done any tests to see if (Container is Form) evaluates to true; I just assumed it would if the container was a form. If it doesn't, that could be the reason why the code isn't running.
Your method may work where the other did not. I'll try it out when I get home.
|
|
|
|
|
Nope, it doesn't work. Upon further inspection, ( containerForm != null ) is evaluating as false, indicating that something is wrong with the typecasting.
I'm thinking it may not be possible to cast a Container to a Form...
...in which case I'll have to do things the hard way: pass the form to the component as a parameter. I'd rather not, though, if I don't have to.
|
|
|
|
|
why don't you do a:
Type containerType = Container.GetType();
and see what the container really is?
|
|
|
|
|
In addition to what Andy wrote your best bet is to code for the lowest common denominator. If you only need to use properties/methods that a control has, then compare to System.Windows.Forms.Control.
The container may not be a form but it could be a Panel, or a UserControl or some other class.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
I thought about that after I had written the code, but I assumed that 'as' was implemented as Container is Form ? (Form) Container : null
Apparently I made an ass of myself :-P
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
well, don't think too badly of yourself.
From the SDK Docs:
-----------------------
The as operator is like a cast except that it yields null on conversion failure instead of raising an exception. More formally, an expression of the form:
expression as type
is equivalent to:
expression is type ? (type)expression : (type)null
except that expression is evaluated only once.
-----------------------
so it is logically exactly as you claim... but the actual IL implementation is different, and not describable with c#... which explains the requirement of the new "as" keyword.
|
|
|
|
|
ah, maybe thats why I thought that
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
Does anyone know what the equivalent would be in C#? System.Drawing.Graphics does not seem to have a means of doing what I want, which is a recangle with rounded corners.
|
|
|
|
|
Charles Petzold's Programming Microsoft Windows with C# has an example demonstrating how to create one.
Unfortunately the code from the book isn't available on his website, nor MSPress' website so I can't give you his exact code.
But I don't think there would be any harm in giving you the algorithm since it is common sense when you think about it
First break up your rounded rectangle up into its distinct sections. You have the four sides, and 4 rounded parts. The rounded parts if you put them together form an ellipse. So all you have to do to create your own rounded rect function is to use the DrawArc and DrawLine methods of the Graphics object to position each part where it needs to be.
HTH,
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
I have written an article showing how it's done, but as the other poster said, it's pretty obvious. I provide a function that allows you to set % rounded, just like GDI did.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
Thanks both of you. I was hoping I was missing something and would not have to do it manually.
I don't understand why they would not have brought RoundRect forward into C#/.NET, it seems like something that would be useful (at least to me).
|
|
|
|
|
okay here is my problem, i have asked this question about a million times, and everybody keeps giving me the same answer...
which leads me to the conclution that nobody understands or knows anything about windows XP themes!!!
basically if you look at the theme example in MSDN (ms-help://MS.MSDNQTR.2002JAN.1033/dnwxp/html/xpvisualstyles.htm) you see that the example is first of all written in c++, and that they dont expand much on how to do any of this in .NET (e.g. c# and vb.net)
now the reason i said that nobody seems to know the answer to this question is that every time i ask it, i get this response
**************************
use a manifest file
**************************
i knew about using manifest for quite a long time now, that is NOT theming in windows XP.
microsoft says that there are new MSLOGO compliancy standards for XP... there are lots of doc's available on the logo site about this, but NONE of them tell you how to do it in .NET!!!!
i find this to be extremely unfair as MS wants us (the developers) to use .net it is only right for them to tell us how to stick to the standards that they Set.?!?!
am i wrong in asking this?
|
|
|
|
|
To enable XP Themed controls in a .NET application you need to do two things. First, include the manifest file; second, set the FlatStyle property of your controls to System.
If you are creating your own controls then you need to use P/Invoke to obtain the functionality needed for themes.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
akr0 wrote:
okay here is my problem, i have asked this question about a million times, and everybody keeps giving me the same answer...
So everyone is wrong and you are right. Congrats to you.
Enlighten everyone and write an article.
|
|
|
|
|
hehehe
Mark Nischalke wrote:
So everyone is wrong and you are right.
i did not say that. what i meant was this, look at james' post, he also makes reference to the manifest file and the flatstyle of controls... this is all fine and well. it gives the illusion of a themed application. but do this and place a tab page control on the form. add two or three tabs.
then run the app, right click on your desktop and goto properties. look at the difference between the actual pages (not the tabs, the page colors)... this is where you need the uxtheme.dll...
Mark Nischalke wrote:
Enlighten everyone and write an article.
there is an idea, i have discovered some things in the last week on how to access normal DLL's and API's... which will enable me to access uxtheme.dll
|
|
|
|
|
akr0 wrote:
then run the app, right click on your desktop and goto properties. look at the difference between the actual pages (not the tabs, the page colors)... this is where you need the uxtheme.dll...
The page color issue is an acknowledged bug by MS.
I'm sure there are other controls where this is a problem though which is why you'll need to P/Invoke to get around it until MS fixes it.
akr0 wrote:
there is an idea
Please do I always look forward to new articles, especially on new topics such as this.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
I know that this topic was discussed, but no-one wrote how to compile manifest as a resource (into the EXE file). So I ask how to do it?
|
|
|
|
|
I'm just about to leave again, but I figured I'd throw this out so you can look at it while I'm gone.
Assuming you are using VS.NET, add the .manifest file to your project as an "Embedded Resource" and see if that works. If not add it as "Content". This option is accessed in the build property for the file.
Let me know if either of those work. I know its possible to do it in VS.NET I just need to remember how.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
I've already tried it and it works neither "Embedded Resource" nor "Content". I think it should be compiled as a Win32 resource and C# compiles it a little bit different (resx). But I'm not sure.
|
|
|
|
|
Who knows how to link all DLL's which an C# app need into one EXE file staticaly. In VS C++ there is a choice called "Use MFC in a Static Library" and then the c++ app runs on every system, but how to do it in C#???
|
|
|
|