Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Desktop Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

Search

XML Feeds

Google Ads

Tags: hack

comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

No visual inheritance doesn’t work in Visual studio (whatever version). You need way to many trickery to get it to work. I’m working on a blogpost that says why VI doesn’t work but it is taking longer then excpected. There are so many things that don’t work.

One thing is the fact that if you inherit from a form that uses generics the designer just gives up and refuses to draw the form at designtime. It has no problem whatsever to display the form when at runtime. But still, if you have a mediumcomplex form it is not desirable to write the code manually.

But for this problem there is a workaround. Actualy it is a dirty filty hack but it works ;-). I found this code while looking at the code for MVC#, I will post about this later too.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using MVCSharp.Winforms;
  9. using MVCSharp.Winforms.Configuration;
  10. using MVCSharp.Examples.WindowsFormsExample.ApplicationLogic;
  11.  
  12. namespace MVCSharp.Examples.WindowsFormsExample.Presentation
  13. {
  14.     [WinformsView(typeof(MainTask), MainTask.MainView, IsMdiParent = true)]
  15.     public partial class MainForm : MainForm_Generic, IMainView
  16.     {
  17.         public MainForm()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         public void SetCurrViewName(string viewName)
  23.         {
  24.             currentViewStatusLbl.Text = viewName;
  25.         }
  26.  
  27.         private void ToolStripMenuItem_Click(object sender, EventArgs e)
  28.         {
  29.            Controller.Navigate((sender as ToolStripMenuItem).Text);
  30.         }
  31.     }
  32.  
  33.     // This intermediate class is used as a workaround for the bug
  34.     // in the VS form designer when inheriting a generic user control class.
  35.     public class MainForm_Generic : WinFormView<MainViewController>
  36.     { }
  37. }

Did you see the trick?

Yep you make an in between class that inherits from the genric form and then your form inherits from that. A dirty filty hack but it works ;-).

About the Author

User bio imageChristiaan is a forensic technician who programs on the side, although my function description says that I do IT-things for 90% of the time . I'm an avid VB.NET fan and I use lots of the ALT.Net techniques, like unit-testing, nhibernate, logging, IoC, ...
Social SitingsTwitterLinkedInHomePageLTD RSS Feed
1772 views
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback