Jump to content
Xtreme .Net Talk

Azrael

Members
  • Posts

    7
  • Joined

  • Last visited

Azrael's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Would it not be better to spawn a thread and do the heavy db work in that? Then when a ui component is changed marshal a call to the ui event q thread with BeginInvoke?
  2. You can use the two following events for uncaught exceptions: [*]UnhandledException [*]ThreadException UnhandledException is in the Domain object and can be used for CLR type exceptions where as the latter will catch unhandled Forms exceptions. For example, in your form code bootstrap you can use something like this: [sTAThread] static void Main() { AppDomain curr_domain = AppDomain.CurrentDomain; curr_domain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler); Application.ThreadException += new ThreadExceptionEventHandler(ThreadExceptionHandler); Application.Run(new The_App()); } and your handlers look like: // do whatever handling you need private static void UnhandledExceptionHandler( object sender, UnhandledExceptionEventArgs args) { Exception e = (Exception)args.ExceptionObject; MessageBox.Show("drat " + e.Message); } // do what ever handling you need private static void ThreadExceptionHandler( object sender, ThreadExceptionEventArgs args) { Exception e = (Exception)args.Exception; MessageBox.Show("oops :: " + e.Message); } Interesting note is the inconsistent naming scheme in the EventArgs, in UnhandledExceptionEventArgs the exception is in the ExceptionObject property where as with the ThreadExceptionEventArgs is in the Exception property. That must have slipped through any code reviews! Also, you will need to change a reg key: HKLM/Software/Microsoft/.NetFramework/DbgJITDebugLaunchSetting to a value other than 2.
  3. Hello, Not sure if this has been done before although a cursory search revealed nothing, so here goes. Problem: When adding items to a listview control they are appended to the list at the bottom (in detail view). The problem is that if you are wanting focus to be on the latest entry it can be abit of a bind, because focus stays at the beginning of the list. We can access the WndProc method to play with this... A Solution: The problem with the control is that the WndProc is protected and so we have to subclass the ListView control and decorate it with a method called AddItem (for instance) thus: public class ScrollerListView : ListView { // values obtained from winusr.h const int WM_SCROLL = 0x0115; const IntPtr SB_BOTTOM = (IntPtr) 7; public void AddItem( ListViewItem new_item ) { // add the item to the items collection Items.Add( new_item ); // have to Create a message Message msg = Message.Create( Handle, // the hwnd handle WM_VSCROLL, // uMsg SB_BOTTOM, // wParam IntPtr.Zero ); // null as not sent by scrollbar // call protected WndProc method WndProc( ref msg ); } } WndProc is implemented in the base class to this control so we don't have to worry about it. We could implement our own, overriding it if we wished to handle certain windows messages ourselves... Cheers PS - and of course it'd be much more graceful to have the winusr definitions elsewhere - rather disappointingly C# doesn't provide them for you...
  4. Just about the defacto base knowledge book on computer graphics is : "Computer Graphics: Principles and Practice in C" by Foley, Van Dam et al... Here are link to it at Amazon
  5. Greets, Apologies if its a bit unclear - I'll give it another bash... Consider a custom control which is going to be used as the view and controller for some underlying data model. At design time you have a form which the control gets dropped onto and placed etc. Now the underlying datamodel (in the earlier example we had a custom tree and a treemodel), is a) a non visual component and b) a cusotm type. The client programmer is going to put a declaration that creates (in the simple case) an instance of that in the form code (won't bother abstracting out a whole document underlying the data that the form is a view of - aka ye olde pDoc*). The tree has a property called Model eg: class Tree { // lots of visual drawing code etc... private TreeModel model; // this will have to be decorated with type designer hints... public TreeModel Model { get { return model; } set { // do some real funky work in here to get the // bloomin thing working (I presume at the moment) } } } The property viewer of the custom tree control shows the property "Model" but it is uneditable - because its a custom type etc. Now the aim is to have design time support (via the UITypeEditor and I presume CodeDom) so that actually, the uieditor can pick up if we have code like this: public class ViewForm : System.Windows.Forms.Form { // the views tree model that represents the underlying // data. The views tree control needs to have a handle // on this. private TreeModel custom_model = new TreeModel(); private Tree custom_tree = new Tree(); // other windows form code and methods etc... } the property grid for the tree control under the Model property will have a selectable intance of custom_model. In other words its discovered our custom type declaration (and any other if we so wished) so when selected (excuse the ascii art ;) ) we'll see. | .. other properties in the display .. | |---------------------------------- -------| |Model | none | V | |--------| custom_model |---| |Size |------------------------------***| |------------------------------------------| it will insert a piece of code such as: public class ViewForm : System.Windows.Forms.Form { // other code private void InitializeComponent() { // this is inserted by the designer by selecting // the discovered instance name of our tree_model custom_tree.Model = custom_model; // other code } } The feature is possible without actually having to do any programming in other language IDE's that shall, remain nameless here ;) The whole crux is that we have a view and a model that need to be linked and it'd be desirable to avoid the necessity of the client programmer having to go enter that assign statement in the InitializeComponent method himself. Is that any better? Thanks for your patience...
  6. Greets, I'd thought as much - but the problem is: a) hooking into the current source code thats being displayed to grab instance names of that custom type that is defined at the head of the code (which will then be displayed in say a custom uitypedesigner dropdown list) so that in the init method the custom control's custom type property is assigned that handle.. b) injecting that back into the current source code - which I assume will be with the CodeDom although that beast at the moment appears akin to black magic ;). Thanks
  7. Hello One and All, I have been kicking around a problem (for a bit of fun) for the last few days and haven't made much progress and am wondering if anyone can point me in the correct direction... My problem: Consider a type that has a custom type property - eg (using an mvc paradigm on a visual component) a tree (the view) which is seperated out from its tree model (the data model). Now I've rooted around at the MSDN docs at design time support and various other hints but they don't seem to answer my question of being able, to say have an instance of the data model instantiated in a section of code and from the properties viewer at design time set a "model attribute" of the tree to point to that model instance. eg: class Foo { // a simple tree model for this example TreeModel model = new TreeModel(); private void initialize() { Tree treeView = new Tree(); // this is the line that I want the designer to be able to // insert into my code from the properties view. The // properties view should autodiscover that a TreeModel // instance has been created in the class already and // offer its name in a drop down combo treeView.setModel( model ); } } Anyone got any helpful pointers or more clear examples of messing around in the CodeDom, Design time stuff and type converters? Regards
×
×
  • Create New...