Click here to Skip to main content
15,891,607 members
Home / Discussions / C#
   

C#

 
QuestionPerformance counter bug? Pin
solidstore22-May-03 7:51
solidstore22-May-03 7:51 
Generalcustom sections in .config files Pin
Anonymous22-May-03 6:43
Anonymous22-May-03 6:43 
GeneralRe: custom sections in .config files Pin
Anonymous22-May-03 6:45
Anonymous22-May-03 6:45 
GeneralRe: custom sections in .config files Pin
Anonymous22-May-03 6:48
Anonymous22-May-03 6:48 
GeneralRe: custom sections in .config files Pin
The Limey22-May-03 16:54
The Limey22-May-03 16:54 
GeneralRe: custom sections in .config files Pin
The Limey22-May-03 16:56
The Limey22-May-03 16:56 
QuestionOwner Drawn Menu item -- Matching Font? Pin
KingTermite22-May-03 6:20
KingTermite22-May-03 6:20 
AnswerRe: Owner Drawn Menu item -- Matching Font? Pin
KingTermite22-May-03 16:06
KingTermite22-May-03 16:06 
Nobody seemed to know, but I was able to figure it out with a little help from this article right here at Code Project:
<url>http://www.codeproject.com/cs/menu/MenuImage.asp

I am reposting my DrawItem as it is now to show the correct way to do so in case anyone else runs into the same question.
<br />
        <COLOR=008000>// DrawItem override for the AddSmiley context menu item owner draw<br />
        </COLOR><COLOR=0000ff>private void </COLOR><COLOR=800080>DrawAddSmileyMenuItem</COLOR>(<COLOR=0000ff>object </COLOR><COLOR=800080>sender</COLOR>,  <COLOR=800080>System</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Windows</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Forms</COLOR><COLOR=008000>.</COLOR><COLOR=800080>DrawItemEventArgs e</COLOR>)<br />
        {<br />
            <COLOR=800080>MenuItem mi </COLOR><COLOR=008000>= </COLOR>(<COLOR=800080>MenuItem</COLOR>)<COLOR=800080>sender</COLOR>;<br />
            <br />
            <COLOR=008000>// Default menu font<br />
            </COLOR><COLOR=800080>Font menuFont </COLOR><COLOR=008000>= </COLOR><COLOR=800080>SystemInformation</COLOR><COLOR=008000>.</COLOR><COLOR=800080>MenuFont </COLOR>;<br />
            <COLOR=800080>SolidBrush menuBrush </COLOR><COLOR=008000>= </COLOR><COLOR=0000ff>null </COLOR>;<br />
            <br />
            <COLOR=008000>// Determine menu brush for painting<br />
            </COLOR><COLOR=0000ff>if </COLOR>( <COLOR=800080>mi</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Enabled </COLOR><COLOR=008000>== </COLOR><COLOR=0000ff>false </COLOR>)<br />
            {<br />
                <COLOR=008000>// disabled text<br />
                </COLOR><COLOR=800080>menuBrush </COLOR><COLOR=008000>= </COLOR><COLOR=0000ff>new </COLOR><COLOR=800080>SolidBrush</COLOR>( <COLOR=800080>SystemColors</COLOR><COLOR=008000>.</COLOR><COLOR=800080>GrayText </COLOR>) ;<br />
            }<br />
            <COLOR=0000ff>else<br />
            </COLOR>{<br />
                <COLOR=0000ff>if </COLOR>( (<COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>State </COLOR><COLOR=008000>& </COLOR><COLOR=800080>DrawItemState</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Selected</COLOR>) <COLOR=008000>!= </COLOR><COLOR=ff0000>0</COLOR>)<br />
                {<br />
                    <COLOR=008000>// Text color when selected (highlighted)<br />
                    </COLOR><COLOR=800080>menuBrush </COLOR><COLOR=008000>= </COLOR><COLOR=0000ff>new </COLOR><COLOR=800080>SolidBrush</COLOR>( <COLOR=800080>SystemColors</COLOR><COLOR=008000>.</COLOR><COLOR=800080>HighlightText </COLOR>) ;<br />
                }<br />
                <COLOR=0000ff>else<br />
                </COLOR>{<br />
                    <COLOR=008000>// Text color during normal drawing<br />
                    </COLOR><COLOR=800080>menuBrush </COLOR><COLOR=008000>= </COLOR><COLOR=0000ff>new </COLOR><COLOR=800080>SolidBrush</COLOR>( <COLOR=800080>SystemColors</COLOR><COLOR=008000>.</COLOR><COLOR=800080>MenuText </COLOR>) ;<br />
                }<br />
            }<br />
<br />
            <COLOR=008000>// Center the text portion (out to side of image portion)<br />
            </COLOR><COLOR=800080>StringFormat strfmt </COLOR><COLOR=008000>= </COLOR><COLOR=0000ff>new </COLOR><COLOR=800080>StringFormat</COLOR>();<br />
            <COLOR=800080>strfmt</COLOR><COLOR=008000>.</COLOR><COLOR=800080>LineAlignment </COLOR><COLOR=008000>= </COLOR><COLOR=800080>System</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Drawing</COLOR><COLOR=008000>.</COLOR><COLOR=800080>StringAlignment</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Center</COLOR>;<br />
<br />
            <COLOR=008000>// Smiley #2 is the image<br />
            </COLOR><COLOR=800080>CSmilies oSmile </COLOR><COLOR=008000>= </COLOR><COLOR=0000ff>new </COLOR><COLOR=800080>CSmilies</COLOR>(<COLOR=ff0000>2</COLOR>);<br />
            <COLOR=800080>Bitmap bmSmiley </COLOR><COLOR=008000>=  </COLOR><COLOR=0000ff>new </COLOR><COLOR=800080>Bitmap</COLOR>(<COLOR=0000ff>typeof</COLOR>(<COLOR=800080>vBCodeGenForm</COLOR>),<COLOR=800080>oSmile</COLOR><COLOR=008000>.</COLOR><COLOR=800080>SmileyIconFileName</COLOR>);<br />
<br />
            <COLOR=008000>// Rectangle for image portion<br />
            </COLOR><COLOR=800080>Rectangle rectImage </COLOR><COLOR=008000>= </COLOR><COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Bounds</COLOR>;<br />
<br />
            <COLOR=008000>// Set image rectangle same dimensions as image<br />
            </COLOR><COLOR=800080>rectImage</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Width </COLOR><COLOR=008000>= </COLOR><COLOR=800080>bmSmiley</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Width</COLOR>;<br />
            <COLOR=800080>rectImage</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Height </COLOR><COLOR=008000>= </COLOR><COLOR=800080>bmSmiley</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Height</COLOR>;<br />
            <COLOR=800080>Rectangle rectText </COLOR><COLOR=008000>= </COLOR><COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Bounds</COLOR>;<br />
            <COLOR=800080>rectText</COLOR><COLOR=008000>.</COLOR><COLOR=800080>X </COLOR><COLOR=008000>+= </COLOR><COLOR=800080>rectImage</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Width</COLOR>;<br />
<br />
            <COLOR=008000>// Start Drawing the menu rectangle<br />
<br />
            // Fill rectangle with proper background <use this instead of e.DrawBackground() ><br />
            </COLOR><COLOR=0000ff>if </COLOR>( (<COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>State </COLOR><COLOR=008000>& </COLOR><COLOR=800080>DrawItemState</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Selected</COLOR>) <COLOR=008000>!= </COLOR><COLOR=ff0000>0</COLOR>)<br />
            {<br />
                <COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Graphics</COLOR><COLOR=008000>.</COLOR><COLOR=800080>FillRectangle</COLOR>(<COLOR=800080>SystemBrushes</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Highlight</COLOR>, <COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Bounds</COLOR>);            }<br />
            <COLOR=0000ff>else<br />
            </COLOR>{<br />
                <COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Graphics</COLOR><COLOR=008000>.</COLOR><COLOR=800080>FillRectangle</COLOR>(<COLOR=800080>SystemBrushes</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Menu</COLOR>, <COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Bounds</COLOR>);            <br />
            }<br />
            <br />
            <COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Graphics</COLOR><COLOR=008000>.</COLOR><COLOR=800080>DrawImage</COLOR>(<COLOR=800080>bmSmiley</COLOR>, <COLOR=800080>rectImage</COLOR>);<br />
            <COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Graphics</COLOR><COLOR=008000>.</COLOR><COLOR=800080>DrawString</COLOR>( <COLOR=800080>mi</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Text</COLOR>, <COLOR=800080>menuFont</COLOR>, <COLOR=800080>menuBrush</COLOR>, <COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Bounds</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Left </COLOR><COLOR=008000>+ </COLOR><COLOR=800080>bmSmiley</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Width</COLOR>, <COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Bounds</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Top </COLOR><COLOR=008000>+ </COLOR>((<COLOR=800080>e</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Bounds</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Height </COLOR><COLOR=008000>- </COLOR><COLOR=800080>menuFont</COLOR><COLOR=008000>.</COLOR><COLOR=800080>Height</COLOR>) <COLOR=008000>/ </COLOR><COLOR=ff0000>2</COLOR>), <COLOR=800080>strfmt </COLOR>) ;<br />
        }<br />



There are only 10 types of people in this world....those that understand binary, and those that do not.
Generalsetting up path for c# Pin
Slow Learner22-May-03 4:44
Slow Learner22-May-03 4:44 
GeneralRe: setting up path for c# Pin
Daniel Turini22-May-03 5:04
Daniel Turini22-May-03 5:04 
GeneralRe: setting up path for c# Pin
Slow Learner23-May-03 9:08
Slow Learner23-May-03 9:08 
GeneralArray of Hashes Pin
JJF00722-May-03 3:48
JJF00722-May-03 3:48 
GeneralRe: Array of Hashes Pin
CBoland22-May-03 8:24
CBoland22-May-03 8:24 
GeneralRe: Array of Hashes Pin
Arjan Einbu22-May-03 8:28
Arjan Einbu22-May-03 8:28 
GeneralRe: Array of Hashes Pin
JJF00722-May-03 22:40
JJF00722-May-03 22:40 
GeneralRe: Array of Hashes Pin
Burt Harris23-May-03 19:00
Burt Harris23-May-03 19:00 
GeneralToolbar HotKey Pin
STW22-May-03 1:54
STW22-May-03 1:54 
QuestionDoes C# have Template like C++ ?? Pin
JeffSayHi21-May-03 23:10
JeffSayHi21-May-03 23:10 
AnswerRe: Does C# have Template like C++ ?? Pin
Giles22-May-03 2:20
Giles22-May-03 2:20 
AnswerRe: Does C# have Template like C++ ?? Pin
Jon Newman22-May-03 5:12
Jon Newman22-May-03 5:12 
QuestionDBF File Read in DataGrid? Pin
bania21-May-03 21:54
bania21-May-03 21:54 
AnswerRe: DBF File Read in DataGrid? Pin
Rocky Moore21-May-03 23:02
Rocky Moore21-May-03 23:02 
GeneralButtons not firing Click event after OpenFileDialog Pin
Arun Bhalla21-May-03 17:38
Arun Bhalla21-May-03 17:38 
GeneralRe: Buttons not firing Click event after OpenFileDialog Pin
Arun Bhalla21-May-03 18:47
Arun Bhalla21-May-03 18:47 
GeneralNode searching in TreeView Pin
azusakt21-May-03 16:17
azusakt21-May-03 16:17 

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.