none
Create a button RRS feed

  • Question

  • Hello All,

    How can i create a button, if i press that button the GraphicWindow will close.


    Thanks
    Yasser Jamil
    Saturday, March 7, 2009 3:59 PM

Answers

  •  Hi,
        moorem34 was posting while I was working on this, but here it is anyway. The OK button is positioned with respect to the right hand lower corner of the GraphicsWindow. Note: It has to be drawn as  a DrawRectangle() and not as a Shapes.AddRectangle() so that it sits in the background layer or the text would be hidden by the Shape.

     

    GraphicsWindow.Show()
    buttonWidth = 50
    buttonHeight = 30
    buttonX = GraphicsWindow.Width - 70
    buttonY = GraphicsWindow.Height - 50
    GraphicsWindow.MouseDown = handleClick
    GraphicsWindow.BrushColor = "LightGray"
    GraphicsWindow.FillRectangle(buttonX, buttonY, buttonWidth, buttonHeight)
    GraphicsWindow.DrawRectangle(buttonX, buttonY, buttonWidth, buttonHeight)
    GraphicsWindow.BrushColor = "Black"
    GraphicsWindow.DrawText(buttonX + 15, buttonY + 7, "OK")

    'Put main program loop here

    Sub handleClick
      xpos = GraphicsWindow.MouseX
      ypos = GraphicsWindow.MouseY
      If(xpos > buttonX And xpos < (buttonX + buttonWidth)) Then
        If(ypos > buttonY And ypos < (buttonY + buttonHeight)) Then
          Program.End()
        EndIf
      EndIf
    EndSub

    The program above doesn't have a main loop but it doesn't seem to matter. I thought I'd better indicate where it should go.
    If this post ends up looking weird it's because this is the second time I've tried to enter this edit.


    • Edited by Stendec Saturday, March 7, 2009 7:07 PM Removed redundant line
    • Marked as answer by Yasser Jamil Saturday, March 7, 2009 7:40 PM
    Saturday, March 7, 2009 5:56 PM
  • Yasser Jamil,

    Try the code below.

    It "hides" the graphics window only if the mouse is pressed inside the rectangle button.

    moorem34

    GraphicsWindow.Width=320
    GraphicsWindow.Height=320
    GraphicsWindow.DrawRectangle(0,0,85,20)
    GraphicsWindow.DrawText(0,0,"Press to Close")

    While buttonclick <> 1
      GraphicsWindow.MouseDown=checkbutton
    EndWhile

    GraphicsWindow.Hide()

    Sub checkbutton
     
      if GraphicsWindow.MouseX >=0 and GraphicsWindow.MouseX <=85 And GraphicsWindow.MouseY >=0 And GraphicsWindow.MouseY <=20 Then
        buttonclick=1
      EndIf
      EndSub


    • Marked as answer by Yasser Jamil Saturday, March 7, 2009 7:40 PM
    Saturday, March 7, 2009 5:27 PM

All replies

  • Yasser Jamil,

    Try the code below.

    It "hides" the graphics window only if the mouse is pressed inside the rectangle button.

    moorem34

    GraphicsWindow.Width=320
    GraphicsWindow.Height=320
    GraphicsWindow.DrawRectangle(0,0,85,20)
    GraphicsWindow.DrawText(0,0,"Press to Close")

    While buttonclick <> 1
      GraphicsWindow.MouseDown=checkbutton
    EndWhile

    GraphicsWindow.Hide()

    Sub checkbutton
     
      if GraphicsWindow.MouseX >=0 and GraphicsWindow.MouseX <=85 And GraphicsWindow.MouseY >=0 And GraphicsWindow.MouseY <=20 Then
        buttonclick=1
      EndIf
      EndSub


    • Marked as answer by Yasser Jamil Saturday, March 7, 2009 7:40 PM
    Saturday, March 7, 2009 5:27 PM
  •  Hi,
        moorem34 was posting while I was working on this, but here it is anyway. The OK button is positioned with respect to the right hand lower corner of the GraphicsWindow. Note: It has to be drawn as  a DrawRectangle() and not as a Shapes.AddRectangle() so that it sits in the background layer or the text would be hidden by the Shape.

     

    GraphicsWindow.Show()
    buttonWidth = 50
    buttonHeight = 30
    buttonX = GraphicsWindow.Width - 70
    buttonY = GraphicsWindow.Height - 50
    GraphicsWindow.MouseDown = handleClick
    GraphicsWindow.BrushColor = "LightGray"
    GraphicsWindow.FillRectangle(buttonX, buttonY, buttonWidth, buttonHeight)
    GraphicsWindow.DrawRectangle(buttonX, buttonY, buttonWidth, buttonHeight)
    GraphicsWindow.BrushColor = "Black"
    GraphicsWindow.DrawText(buttonX + 15, buttonY + 7, "OK")

    'Put main program loop here

    Sub handleClick
      xpos = GraphicsWindow.MouseX
      ypos = GraphicsWindow.MouseY
      If(xpos > buttonX And xpos < (buttonX + buttonWidth)) Then
        If(ypos > buttonY And ypos < (buttonY + buttonHeight)) Then
          Program.End()
        EndIf
      EndIf
    EndSub

    The program above doesn't have a main loop but it doesn't seem to matter. I thought I'd better indicate where it should go.
    If this post ends up looking weird it's because this is the second time I've tried to enter this edit.


    • Edited by Stendec Saturday, March 7, 2009 7:07 PM Removed redundant line
    • Marked as answer by Yasser Jamil Saturday, March 7, 2009 7:40 PM
    Saturday, March 7, 2009 5:56 PM