sharing about .NET and technology RSS 2.0
# Thursday, February 22, 2007

In many enterprise applications there is the need that, regardless on which control you have the focus, that you can hit the 'Enter' and/or 'Esc' key to perform a default action. This behaviour is also common to web applications. On the Form control you find properties like AcceptButton and CancelButton, whereas the UserControl doesn't have these properties. The code below contains an AcceptButton and CancelButton that allows you to define a default action when the Enter or Esc key is pressed respesctively.

public class UserControlEx : System.Windows.Forms.UserControl
{    
    private Button _acceptButton;
    private Button _cancelButton;

    public event EventHandler<EventArgs> AcceptEvent;
    public event EventHandler<EventArgs> CancelEvent;

    [Browsable(true)]
    public Button AcceptButton
    {
        get { return _acceptButton; }
        set { _acceptButton = value; }
    }

    [Browsable(true)]
    public Button CancelButton
    {
        get { return _cancelButton; }
        set { _cancelButton = value; }
    }

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (msg.WParam.ToInt32() == (int)Keys.Enter)
        {
            OnAcceptEvent(EventArgs.Empty);

            if (_acceptButton != null)
                _acceptButton.PerformClick();
        }

        if (msg.WParam.ToInt32() == (int)Keys.Escape)
        {
            OnCancelEvent(EventArgs.Empty);

            if (_cancelButton != null)
                _cancelButton.PerformClick();
        }

        return base.ProcessCmdKey(ref msg, keyData);
    }

    protected virtual void OnAcceptEvent(EventArgs args)
    {
        if (AcceptEvent != null)
            AcceptEvent(this, args);
    }

    protected virtual void OnCancelEvent(EventArgs args)
    {
        if (CancelEvent != null)
            CancelEvent(this, args);
    }
}
Thursday, February 22, 2007 10:32:31 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [3] -
.NET | Windows Forms
# Sunday, April 23, 2006

One of the ways for extending the WebBrowser 2.0 control is to inherit from WebBrowserSiteBase. According to the documentation, you have to override the method CreateWebBrowserSiteBase and return your specific implementation of WebBrowserSiteBase.

Everything is there to plug-in your implementation of WebBrowserSiteBase, but the problem is that the constructor of WebBrowserSiteBase is marked as internal, and so there is no way to inherit from. I am pretty sure that it was possible with the beta release of .NET 2.0, but for some reason they marked it as internal in the RTM version. This means that implementing some interfaces that are described here are not possible.

I am planning to release a .NET 2005 version of my IStaySharp.WebBrowser project. More info coming soon.

Sunday, April 23, 2006 8:43:56 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [3] -
.NET | Windows Forms
# Thursday, February 23, 2006

CAB is an application block for building smart clients in .NET 2.0 and contains proven practices for building complex UI forms with so called SmartParts and Workspaces. The DeckWorkspace enables you to show and hide controls and SmartParts in an overlapped manner with no visible frame.

If you switch between controls, you will notice that the controls are painted while there are initializing. During the loading you will see that there is some overlapping and it doesn't give you a professional user experience.

Therefore I extended the DeckWorkspace, so that the the controls are only redrawed when they are initialized. This can be done through the WM_SETREDRAW message. Note that this technique can also be used for other workspaces.

public class DeckWorkspaceEx: DeckWorkspace
{ 
   int freezePainting = 0;
   const int WM_SETREDRAW = 0xB;

   [DllImport("User32")]
   static extern bool SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

   protected void FreezePaintingOn()
   {
      if (IsHandleCreated && this.Visible)
      {
         if (0 == freezePainting++)
         {
            SendMessage(Handle, WM_SETREDRAW, 0, 0);
         }
      }
   }

   protected void FreezePaintingOff()
   {
      if (freezePainting != 0)
      {
         if (0 == --freezePainting)
         {
            SendMessage(Handle, WM_SETREDRAW, 1, 0);
            Invalidate(true);
         }
      }
   }

   protected override void OnActivate(Control smartPart)
   {
      FreezePaintingOn();
      try 
      {
         base.OnActivate(smartPart);
      }
      finally 
      {
         FreezePaintingOff();
      }
   }

   protected override void OnClose(Control smartPart)
   {   
      FreezePaintingOn();
      try 
      {
         base.OnClose(smartPart);
      }
      finally 
      {
         FreezePaintingOff();
      }
   }

   protected override void OnHide(Control smartPart)
   {
      FreezePaintingOn();
      try 
      {
         base.OnHide(smartPart);
      }
      finally 
      {
         FreezePaintingOff();
      }
   }   

   protected override void OnShow(Control smartPart, SmartPartInfo smartPartInfo)
   {
      FreezePaintingOn();
      try 
      {
         base.OnShow(smartPart, smartPartInfo);
      }
      finally 
      {
         FreezePaintingOff();
      }
   }
}
Thursday, February 23, 2006 1:14:56 AM (Romance Standard Time, UTC+01:00) -  # -  Comments [4] -
.NET | Windows Forms
# Friday, September 23, 2005

I updated the IStaySharp.WebBrowser control with some bug fixes.

  • DocumentText fix in IEBrowser
  • Fix of member TranslateAccelerator in IDocHostUIHandler
  • ScrollBarsEnabled fix in IEBrowserSiteBase

More information can be found on IStaySharp.

Friday, September 23, 2005 12:29:29 AM (Romance Daylight Time, UTC+02:00) -  # -  Comments [5] -
.NET | WebBrowser | Windows Forms
# Sunday, April 10, 2005

I've added a FAQ entry named 'How to send data between forms' to IStaySharp that shows you how to send data with the COPYDATASTRUCT and SENDMESSAGE function.

Sunday, April 10, 2005 7:17:25 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [2] -
.NET | Windows Forms
# Tuesday, February 08, 2005

If it depends on Shawn Burke (Developer Division Program Manager) it must be possible to ship the Windows Forms source code and PDBs in version .NET 2.0. More information about that great idea can be found on the blog

Tuesday, February 08, 2005 12:02:18 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [0] -
.NET | Windows Forms
# Thursday, June 17, 2004

The last couple of weeks I concentrated on writing SharpBrowser. It was already subscribed for a long time on Sourceforge.net, but now I finally released an initial version :-).

The main features of the initial version, is that it is tab-based and it can be used with IE or Mozilla! SharpBrowser uses the great UI library from divil.co.uk for the menus, toolbars, docking and documents. One of the features is that you for example can choose the UI rendering, e.g.: Office2003, Everett and Whidbey.

In order to use Mozilla you just have to download the Mozilla 1.7 ActiveX Control and install it. If the installation is successful you will see an extra menuitem, where you can choose the browser:
(left is IE, right is Mozilla)

Note that this is an initial release, and that there a bunch of features that must be implemented. In the following weeks I will concentrate on implementing features that are included in the standard IE and after that extra features like:

  • cookie mamagement
  • download management
  • popup killer
  • google toolbar
  • view partial source
  • event viewer
  • manage broken links
  • mouse gestures
  • plugin-mechanism
  • etc.

That's why I started writing SharpBrowser, because I am convinced that you can implement a set of very usefull features for a browser that are not (yet) included in IE. I am also thinking about features for web developers, like a viewstate decoder, better support for debugging javascript, test scenarios, etc.

This project give me also the opportunity to experiment with libraries like MyXaml, log4net, Microsoft Application Blocks, etc. For me it is important that I can learn of it, and that the project uses the right concepts, design patterns, libraries, etc. That's the reason why I distribute it in open-source so that we can share our knowledge!

In the next couple of days I will explain some concepts that I implemented for SharpBrowser. Patterns like the visitor, command, composite, facade, etc.

If you have any suggestions, ideas for new features, or want to share about good practices, design patterns, libraries, please let me know! You can send an email to me@delarou.name

SharpBrowser v0.5 (1,79 MB)
(source code will be available in a couple of days)

Thursday, June 17, 2004 1:37:46 AM (Romance Daylight Time, UTC+02:00) -  # -  Comments [8] -
.NET | WebBrowser | Windows Forms
# Tuesday, April 20, 2004

Today I published the first version of the library delarou.Browser. The aim of the library is to wrap the browser functionality of Internet Explorer and Mozilla. It acts like a normal windows control in your toolbox and you can easily drag and drop the controls IEBrowser and/or MozillaBrowser on your designer surface. More information about the library can be found here.

Below you find a screenshot of the demo application (top MSIE, bottom Mozilla):

This library is an initial version and will frequently be updated, because this is a part of a bigger project that I am working on, namely SharpBrowser (more details about that project will come soon). Note that the control IEBrowserHost is not yet intended for use, it’s still in development

Tuesday, April 20, 2004 11:30:00 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [4] -
.NET | WebBrowser | Windows Forms
Navigation
Archive
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Christoph De Baene
Sign In
Statistics
Total Posts: 176
This Year: 2
This Month: 0
This Week: 0
Comments: 249
All Content © 2010, Christoph De Baene
DasBlog theme 'Business' created by Christoph De Baene