Welcome to Sign in | Help
in Search

Background image to a button Visual C#

Last post 05-23-2008, 6:51 PM by rsocol. 5 replies.
Sort Posts: Previous Next
  •  05-22-2008, 9:23 PM 5013

    Background image to a button Visual C#

    Buna,

    Trebuie sa pun o imagine pe un custom button. Am creat o clasa separata de butoane , pe care apoi intentionez sa o adaug in toolbox (ca sa ma pot folosi de butonul nou creat).

    Nu stiu cum sa adaug o imagine pe un buton.Aveti vreo idee?

    Mersi de ajutor!

  •  05-23-2008, 9:29 AM 5017 in reply to 5013

    Re: Background image to a button Visual C#

    custom button -ul tau e derivat din Button ?
    Sau din usercontrol ?

    Ignat Andrei
    http://serviciipeweb.ro/iafblog
  •  05-23-2008, 10:26 AM 5023 in reply to 5013

    Re: Background image to a button Visual C#

    Asta chiar că mi se pare o întrebare pentru RONUA, nu pentru ROSQL.
    Dar hai, fie... Ai creat un UserControl sau un Custom Control ?

    Dacă ai creat un UserControl, e banal: pui BackgroundImage şi gata.

    Dacă ai creat un Custom Control atunci cred că trebuie să faci ceva de genul:

            protected override void OnPaint(PaintEventArgs pe)
            {
                Graphics g = pe.Graphics;
                g.DrawImage(global::MyApplication.Properties.Resources.MyPicture,new Point(0,0));
                base.OnPaint(pe);
            }

    Răzvan
  •  05-23-2008, 5:38 PM 5029 in reply to 5023

    Re: Background image to a button Visual C#

    Este un CustomControl. Eu de fapt vreau sa aliniez la stanga un text pe un buton. Dar nush sa converstesc anumite metode din Windows Control Library ... in Smart Device Control Library...pt ca metodele nu sunt aceleasi...asa ca m-am gandit sa inserez nishte imagini cu textul meu.

    Aveti vreo idee de conversie?

    Acesta este codul in Windows Control Library:

    protected override void OnPaint(PaintEventArgs e)

    {

    // Calling the base class OnPaint

    base.OnPaint(e);

    string text2 = " Biblioteca";

    using (Font font2 = new Font("Arial", 11, FontStyle.Bold, GraphicsUnit.Point))

    {

    Rectangle rect2 = new Rectangle(0, 0, 170, 30);

    // Create a TextFormatFlags with // Create a TextFormatFlags with left, vertical center and single line alignment.

    TextFormatFlags flags = TextFormatFlags.Left |

    TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine;

    // Draw the text and the surrounding rectangle.

    TextRenderer.DrawText(e.Graphics, text2, font2, rect2, Color.Black, flags);

    e.Graphics.DrawRectangle(Pens.Black, rect2);

    }

    }

     

    Mersi mult!

  •  05-23-2008, 5:39 PM 5030 in reply to 5017

    Re: Background image to a button Visual C#

    Da, CustomButton-ul e derivat din Button.
  •  05-23-2008, 6:51 PM 5031 in reply to 5029

    Re: Background image to a button Visual C#

    Încearcă ceva de genul:

            protected override void OnPaint(PaintEventArgs e)
            {

                base.OnPaint(e);

                string text2 = " Biblioteca";
                using (Font font2 = new Font("Arial", 11, FontStyle.Bold))
                {
                    Rectangle rect2 = new Rectangle(0, 0, 170, 30);
                    e.Graphics.DrawRectangle(new Pen(Color.Black), rect2);

                    Rectangle rect1 = new Rectangle(0, 7, 170, 15);
                    e.Graphics.DrawString(text2, font2, new SolidBrush(Color.Black), rect1);
                }               
            }

    Răzvan

    PS. E prima dată când scriu cod C# pentru un Smart Device...
View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems