Special button

Discussion in 'Questions (Windows Mobile)' started by PatrikL, Oct 13, 2009.

  1. PatrikL

    PatrikL Member Licensed User

    Hi everybody,

    I want create image button with 2 lines of text and with one small picture.

    Code:
    picbutton_Create("Form1","Butt1"10106040"Text1""Text2",ImageList1.Item(1),ImageList1.Item(0))

    Sub picbutton_Create (Owner, Name, Left, Top, Width, Height, Text1, Text2, Background, Picture)
       AddPanel(Owner,Name,Left,Top,Width,Height)
       AddImage(Name,
    "im"&Name,00, Width, Height)
       
    Control("im"&Name,Image).Mode = cStretchImage
       
    Control("im"&Name,Image).Transparent = False
       
    Control("im"&Name,Image).Image = Background
       pomoc = 
    Round((Height-28)/3)
       
    'AddLabel(Name,"lb1"&Name,23,pomoc+3,Width-25,12,Text1)
       'Control("lb1"&Name,Label).FontSize=10
       'Control("lb1"&Name,Label).BringToFront
       AddLabel(Name,"lb2"&Name,2,2*pomoc+16,Width-4,12,Text2)
       
    'Control("lb2"&Name,Label).FontSize=12
       Control("lb2"&Name,Label).BringToFront
       AddImage(Name,
    "ip"&Name,2,pomoc,16,16)
       
    Control("ip"&Name,Image).Image = Picture
       
    Control("ip"&Name,Image).BringToFront
       AddEvent(
    "im"&Name,Click,"picbutton_Click")
       AddEvent(
    "ip"&Name,Click,"picbutton_Click")
    End Sub
    First problem is that Label have background, so its look nasty.

    Second problem is that Label dont have Click event, so I cant make reaction on it.

    I try use DrawString but this works only on Form....

    I cant found solution, how create button what I want. Please write me any idea...

    Thx.
     
  2. JOTHA

    JOTHA Well-Known Member Licensed User

    Hi PatrikL,

    Did you use a "ImageButton"?

    You can also use it has a behavior like a "Label". Just try it. :cool:
     
  3. PatrikL

    PatrikL Member Licensed User

    Its better, but isnt 100% correct solution. If I click on ImageButton text is moving little....

    Code:
    Sub picbutton_Create (Owner, Name, Left, Top, Width, Height, Text1, Text2, Background, Picture)
       AddPanel(Owner,Name,Left,Top,Width,Height)
       AddImage(Name,
    "im"&Name,00, Width, Height)
       
    Control("im"&Name,Image).Mode = cStretchImage
       
    Control("im"&Name,Image).Transparent = False
       
    Control("im"&Name,Image).Image = Background
       pomoc = 
    Round((Height-28)/3)
       AddImageButton(Name,
    "lb1"&Name,23,pomoc+3,Width-25,12,Text1)
       
    Control("lb1"&Name,ImageButton).Transparent = False
       
    Control("lb1"&Name,ImageButton).Image = Background
       
    Control("lb1"&Name,ImageButton).BringToFront
       AddImageButton(Name,
    "lb2"&Name,2,2*pomoc+16,Width-4,12,Text2)
       
    Control("lb2"&Name,ImageButton).Transparent = False
       
    Control("lb2"&Name,ImageButton).Image = Background
       
    Control("lb2"&Name,ImageButton).BringToFront
       AddImage(Name,
    "ip"&Name,2,pomoc,16,16)
       
    Control("ip"&Name,Image).Image = Picture
       
    Control("ip"&Name,Image).BringToFront
       AddEvent(
    "im"&Name,Click,"picbutton_Click")
       AddEvent(
    "lb1"&Name,Click,"picbutton_Click")
       AddEvent(
    "lb2"&Name,Click,"picbutton_Click")
       AddEvent(
    "ip"&Name,Click,"picbutton_Click")
    End Sub
     
  4. klaus

    klaus Expert Licensed User

    Here you have a solution using the ImageLibEx library. The whole button image is drawn onto a BitmapEx object and then the bitmap is copied to the button.

    The 2 upper buttons are Image controls
    and the 3rd oune is an ImageButton control.

    The text in the 1st button is centered in the height and with CfLf between Text1 and Text2.
    In the 2 lower buttons the 2 texts are symetrically centered in the height.

    The images for Background and Picture are in an ImageList control.
    In the calling code line, Background and Picture are the indexes of the images in the ImageList control.

    Code example for the upper button.
    Code:
    [SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]App_Start[/COLOR][/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New]PicButton1_Create([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"frmMain"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"btnImage1"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]40[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]120[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]60[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Stop"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Button1"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New]...[/FONT][/SIZE][/SIZE][/FONT]
     
    Sub [/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]PicButton1_Create(Owner, Name, Left, Top, Width, Height, Text1, Text2, Background, Picture)[/SIZE][/FONT]
    [/SIZE][/
    FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] txt,hh[/SIZE][/FONT]
    [/SIZE][/
    FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] AddImage[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](Owner,Name,Left,Top,Width,Height)[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New] bmpImage.New2(Width,Height)[/FONT][/SIZE]
    [SIZE=
    2][FONT=Courier New] drwImage.New2(bmpImage.Value)[/FONT][/SIZE]
    [SIZE=
    2][FONT=Courier New] drwImage.SetTransparentColor=[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]cWhite[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/
    FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] brush1.New1([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]cBlue[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New] font1.New1([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Arial"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New] drwImage.Font=font1.Value[/FONT][/SIZE]
    [SIZE=
    2][FONT=Courier New] rectSrc.New1([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],Width,Height)[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New] rectDest.New1([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],Width,Height)[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New] drwImage.DrawImage(IL1.Item(Background),rectSrc.Value,rectDest.Value,[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]False[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New] rectSrc.New1([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],Il1.Width(Picture),Il1.Height(Picture))[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New] hh=(Height-IL1.Height(Picture))/[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/
    FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] rectDest.New1(hh,hh,Il1.Width(Picture),Il1.Height(Picture))[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New] drwImage.DrawImage(IL1.Item(Picture),rectSrc.Value,rectDest.Value,[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]True[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New] txt=Text1&[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]CRLF[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]&Text2[/SIZE][/FONT]
    [SIZE=
    2][FONT=Courier New] hh=drwImage.StringHeight(txt)[/FONT][/SIZE]
    [SIZE=
    2][FONT=Courier New] drwImage.DrawString1(Text1&[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]CRLF[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]&Text2,brush1.Value,Height,(Height-hh)/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [/SIZE][/
    FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] Control[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](Name,Image).Image=bmpImage.Value[/SIZE][/FONT]
    [/SIZE][/
    FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] AddEvent[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](Name,Click,Name&[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"_Click"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [/SIZE][/
    FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/
    FONT][/COLOR][/SIZE][/FONT]
    Below the image of the examples and attached the test code.

    Best regards.
     

    Attached Files:

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice