XRC Sub-Classing Questions
"Michael S. Muegel" <[email protected]>
| Newsgroups | gmane.comp.lib.wxwindows.wxnet |
|---|---|
| Message-ID | <[email protected]> |
I'm experimenting with the new XRC sub-classing with .NET hosted classes.
Bryan added this to CVS recently and I added a few tweaks to the way
assemblies and namespaces are specified / looked up.
I have two questions. My sample code and XRC file can be downloaded here:
http://www.muegel.org/xfer/TestXRCSubclassing.zip
I also appended the .cs file to the end of this message.
In my example I am sub-classing Button (with Xbutton). When I make any
changes to the instance in the constructor those changes are ignored.
1) Why are changes within the constructor ignored? The constructor is
called, but changes have no effect. Is the XRC stuff setting various
defaults after construction?
I trapped the EVT_UPDATE_UI event and made changes in there. This worked. I
had to ensure I only made the change once. If my problem with (1) is just
how things are, we'll need to have an event or virtual method which is
called once after sub-class construction when it is safe to make changes to
the instance.
Or I'm doing something really stupid. If so, I'll use my current cold as an
excuse ;-).
My sub-class tweak in this example entailed making the font bigger. So my
next question is:
2) What is the easiest way of ensuring everything resizes correctly after I
make my changes? In this case the button needs to grow a bit.
This sample probably will crash when you try to close it. I was testing a
dialog without a parent window and did not set everything up correctly.
Thanks,
-Mike
--
Michael S. Muegel
Dallas, TX
using System;
using System.Drawing;
using wx;
namespace TextXRCSubclassingNamespace
{
public class XButton : Button
{
public XButton() : base()
{
Console.WriteLine("XButton constructor");
Change_Button(); // setting font here has no effect
EVT_UPDATE_UI(this.ID, new
EventListener(OnUpdateUIEvent));
}
void Change_Button()
{
Console.WriteLine("Setting button font");
this.Font = new wx.Font(13, wx.FontFamily.wxSWISS,
wx.FontStyle.wxNORMAL, FontWeight.wxBOLD, false, "Tahoma");
this.Label = "<I Was Modified>";
}
private bool IgnoreOnUpdateUIEvent = false;
void OnUpdateUIEvent(object sender, wx.Event e)
{
if (! IgnoreOnUpdateUIEvent)
{
IgnoreOnUpdateUIEvent = true;
Console.WriteLine("OnUpdateUIEvent");
// setting font here has effect
Change_Button();
}
}
}
public class XrcDialog : Dialog
{
public XrcDialog() : this(null)
{
}
public XrcDialog(Window parent)
{
XmlResource.Get().LoadDialog(this, parent,
"sa_dialog");
}
}
public class XrcApp : App
{
public override bool OnInit()
{
XmlResource.Get().InitAllHandlers();
XmlResource.Get().Load("UnhandledError.xrc");
XrcDialog dialog = new XrcDialog();
dialog.Show(true);
return true;
}
[STAThread]
static void Main()
{
XrcApp app = new XrcApp();
app.Run();
}
}
}
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click