Click here to Skip to main content
13,861,281 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 23 Dec 2017
Licenced CPOL

Preventing Classes Derived from PrintDocument (and Other Components) from Opening in the Designer by Default

, 23 Dec 2017
Rate this:
Please Sign up or sign in to vote.
Does your derived class open in the Visual Studio Designer while having no UI? Annoying, isn't it? This is simple to fix.


If you derive a class from Component, then Visual Studio assumes it's a UI element. Unfortunately, PrintDocument is derived from Component - and isn't visual at all, it just uses graphics to draw onto output contexts. But your class counts as a visual element as well despite having no UI, so VS will open it in the design view.

Which promptly brings up a blank screen and invites you to add UI elements to it. :sigh:

To Fix It Is Simple

Just add an attribute to your class definition:

/// <summary>
/// Prints Label sheet.
/// </summary>
/// <remarks>
/// Note the addition of the ComponentModel.DesignerCategory attribute.
/// Without this, the class will always open in the designer by default as
/// PrintDocument derives from Component, which VS believes is a visual element.
/// It isn't - you can't display it if try - but that means it opens in the
/// design view: which promptly complains that you need to add items to it.
/// </remarks>
public class MyPrinter : PrintDocument
Now VS will put the icon back to normal, and open in the code view.


  • 2017-12-23 First version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

You may also be interested in...

Comments and Discussions

QuestionMuch greater usability than you indicate Pin
RenniePet3-Jan-18 4:14
memberRenniePet3-Jan-18 4:14 
GeneralMy vote of 5 Pin
Member 373058726-Dec-17 1:40
memberMember 373058726-Dec-17 1:40 
GeneralRe: My vote of 5 Pin
OriginalGriff26-Dec-17 2:43
protectorOriginalGriff26-Dec-17 2:43 
GeneralMy vote of 5 Pin
Heriberto Lugo24-Dec-17 16:55
memberHeriberto Lugo24-Dec-17 16:55 
GeneralRe: My vote of 5 Pin
OriginalGriff26-Dec-17 2:43
protectorOriginalGriff26-Dec-17 2:43 
QuestionIt's amazing ... Pin
Richard MacCutchan23-Dec-17 3:41
protectorRichard MacCutchan23-Dec-17 3:41 
AnswerRe: It's amazing ... Pin
OriginalGriff23-Dec-17 7:09
protectorOriginalGriff23-Dec-17 7:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190214.1 | Last Updated 23 Dec 2017
Article Copyright 2017 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid