KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Help wanted
Goto page Previous  1, 2
 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
pvds
KiXforms Follower
KiXforms Follower


Joined: 01 Apr 2003
Posts: 19
Location: Netherlands

PostPosted: Wed Oct 11, 2006 7:57 pm    Post subject: Its working?! Reply with quote

I was struggling to dispose a bitmap!!!
Have found a solution to the problem it is not pritty but it works.
Code:
Do
   $Bitmap.dispose
   $Panel1.BackgroundImage = $Orginal
   Del $photo
Until @ERROR = 0


This is the final code and one question.
How to set a default button?


Code:
Break On

$Rect_Width = 86
$Rect_Height = 120
$Photo = @SCRIPTDIR + "\Foto\my pic.jpg"
$New_PhotoPath = @SCRIPTDIR + "\Foto\"
$Empty_Photo = @SCRIPTDIR + "\Foto\Leeg.jpg"

$System = CreateObject("Kixforms.System")

$Bitmap = $System.Bitmap($Photo)

   $Form = $System.Form
   $Form.ClientWidth = 352
   $Form.ClientHeight = 358
   $Form.Text = "OSG PasFoto Creator."
   
   $Timer1 = $System.timer()
   $Timer1.Interval = 150
   $Timer1.Tick = "Check_Photo()"
      
   $Panel1 = $Form.Controls.Add($System.Panel())
   $Panel1.Top = 0
   $Panel1.Left = 0
   $Panel1.Width = 352
   $Panel1.Height = 288
   $Panel1.MouseMove = "PanelMouseMove($$System.Sender,$$System.EventArgs)"
      
   $TextBox1 = $Form.Controls.Add($System.TextBox())
   $TextBox1.Top = $Panel1.Height + 10
   $TextBox1.Left = 10
   $TextBox1.Text = "Nummer?"
   $TextBox1.Width = 100
   $TextBox1.Height = 20
   $TextBox1.Enter = "Check_Photo()" ;"SaveImage($MouseX, $MouseY)"
   ;$TextBox1.AcceptsReturn = False

   $Button1 = $Form.Controls.Add($System.Button())
   $Button1.Top = $TextBox1.Top + 30
   $Button1.Left = $TextBox1.Left
   $Button1.Text = "Opslaan"
   $Button1.Click = "SaveImage($MouseX, $MouseY)"
   $Button1.Width = 100
   $Button1.Height = 20
   ;$Button1.Default = True
   
   $label1 = $Form.Controls.Add($System.Label())
   $label1.Top = $TextBox1.Top
   $label1.Left = $TextBox1.Left + 170
   $label1.Text = ""
   $label1.Width = 150
   $label1.Height = 30
   $label1.FontSize = 10
   $label1.FontBold = 1
   $label1.ForeColor = $System.Color.Black
   
   $label2 = $Form.Controls.Add($System.Label())
   $label2.Top = $Form.ClientHeight - 15
   $label2.Left = $Form.ClientWidth - 80
   $label2.Text = "Wouter Beens"
   $label2.ForeColor = $System.Color.DarkGray
      
   $Timer1.Start
   
   $Form.Center
   $Form.Show
   
   While $Form.Visible
      $= Execute($Form.DoEvents)
   Loop
Exit 0

Function Draw_Rect($MouseX, $MouseY)
   $Bitmap.dispose
   $Bitmap = $System.Bitmap($Photo);
   $Plaatje = $System.Graphics.FromImage($Bitmap)
   
   If ($Bitmap <> "")
      $Pen = $System.Pen($System.Color.DarkSlateBlue,3)
      $Plaatje.DrawRectangle($Pen,$MouseX,$MouseY,$Rect_Width,$Rect_Height)
      $Panel1.BackgroundImage = $Bitmap
      $Bitmap = $System.Bitmap($Photo)
      $Panel1.Refresh()
      $Plaatje = 0
   EndIf
EndFunction

Function PanelMouseMove($Sender,$EventArgs)
   If ($Panel1.MouseButtons & $System.MouseButtons_Left)
      $MouseY = $Panel1.MousePosition.y - $form.top - 20
      $MouseX = $Panel1.MousePosition.x - $form.Left - $panel1.Left
      Draw_Rect($MouseX, $MouseY)
   EndIf
EndFunction

Function SaveImage($MouseX, $MouseY)
   $check = Val($Textbox1.Text)
   $Orginal = $System.Bitmap($Empty_Photo)
   
   Select
      Case $TextBox1.Text = "Nummer?" And $Bitmap <> ""
      
         $label1.ForeColor = $System.Color.Red
         $label1.Text = "Huidige Foto wordt verwijderd"
         
         ;$Panel1.BackgroundImage = $Orginal
         
         Do
            $Bitmap.dispose
            $Panel1.BackgroundImage = $Orginal
            Del $photo
         Until @ERROR = 0
         
         $Panel1.Refresh()
         $Timer1.start
      Case 1
         If $check = 0 Or Len($check) <> 6
            $label1.ForeColor = $System.Color.Red
            $label1.Text = "Invul Fout"
         Else
            If Exist($New_PhotoPath + $Textbox1.Text + ".jpg")
               $label1.ForeColor = $System.Color.Red
               $label1.Text = "Bestaat al"
            Else
               If($Bitmap <> "")
                  $NewImage = $Bitmap.Clone($MouseX,$MouseY,$Rect_Width,$Rect_Height)
                  $NewImage.Save($New_PhotoPath + $TextBox1.Text + ".jpg")
                                 
                  $TextBox1.Text = "Nummer?"
                  
                  $label1.ForeColor = $System.Color.Black
                  $label1.Text = "Opslaan"
                  
                  ;$Panel1.BackgroundImage = $Orginal
                  
                  Do
                     $Bitmap.dispose
                     $Panel1.BackgroundImage = $Orginal
                     Del $photo
                  Until @ERROR = 0
                  
                  $Panel1.Refresh()
                  $Timer1.start
               EndIf
            EndIf
         EndIf
   EndSelect      
EndFunction

Function Check_Photo()
   If Dir($Photo) <> ""
      $Timer1.Stop
      Draw_Rect($MouseX, $MouseY)
      $label1.Text = ""
   Else
      $label1.ForeColor = $System.Color.Black
      $label1.Text = "Wacht op Foto"
      $Orginal = $System.Bitmap($Empty_Photo)
      $Panel1.BackgroundImage = $Orginal
   EndIf
EndFunction


Thank for al the Help,
Peter


Last edited by pvds on Wed Oct 11, 2006 8:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Wed Oct 11, 2006 8:05 pm    Post subject: Reply with quote

You can use the .setfocus method.

I am assuming that you want to have a specific button always be the default if the user just hits enter.....

If so you may need a second loop that is always resetting it to your default button as each time the user clicks on something else the focus is set to whatever they have clicked on.

If not. Then just before you show the form, just set whatever buttun with the .setfocus

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
pvds
KiXforms Follower
KiXforms Follower


Joined: 01 Apr 2003
Posts: 19
Location: Netherlands

PostPosted: Wed Oct 11, 2006 8:33 pm    Post subject: Reply with quote

In the Help I found Acceptsreturn.

Quote:
Property Value
True if the ENTER key creates a new line of text in a multiline version of the control; false if the ENTER key activates the default button for the form. The default is true.

Remarks
If the value of this property is false, the user must press CTRL+ENTER to create a new line in a multiline TextBox control. If there is no default button for the form, then the ENTER key will always create a new line of text in the control, no matter what the value of this property.

This is why i want to set a default button.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group