#186149 - 2008-03-12 04:29 AM
Easy123 Business Card Maker
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Here is a quicky example script for loading an image, drawing on the image, than saving the image back to a file.
Easy123 Business Card Maker
Requires the latest and greatest Kixforms.Net
Download the script and template from here
The screenshot:
The code:
Break On
$System = CreateObject("Kixforms.System")
$Form = $System.Form()
$Form.Text = "Easy123 Business Card Maker"
$Form.ClientWidth = 640
$Form.ClientHeight = 300
$Form.FontSize = 10
$PictureBox = $Form.Controls.Add($System.PictureBox())
$PictureBox.BackColor = $System.Color.AppWorkspace
$PictureBox.Dock = $System.DockStyle_Fill
$PictureBox.BorderStyle = $System.BorderStyle_Fixed3D
$Splitter = $Form.Controls.Add($System.Splitter())
$Splitter.Dock = $System.DockStyle_Left
$Panel = $Form.Controls.Add($System.Panel())
$Panel.Dock = $System.DockStyle_Left
$OpenButton = $Panel.Controls.Add($System.Button())
$OpenButton.Left = 10
$OpenButton.Top = 5
$OpenButton.Width = 150
$OpenButton.Text = "1) Open a template..."
$OpenButton.TextAlign = $System.ContentAlignment_MiddleLeft
$OpenButton.Enabled = 1
$OpenButton.Click = "OpenButton_Click($$System.Sender, $$System.EventArgs)"
$GoButton = $Panel.Controls.Add($System.Button())
$GoButton.Left = 10
$GoButton.Top = $OpenButton.Bottom + 5
$GoButton.Width = 150
$GoButton.Text = "2) Make my card --->"
$GoButton.TextAlign = $System.ContentAlignment_MiddleLeft
$GoButton.Enabled = 0
$GoButton.Click = "GoButton_Click($$System.Sender, $$System.EventArgs)"
$TextBox = $Panel.Controls.Add($System.TextBox())
$TextBox.MultiLine = 1
$TextBox.Left = 10
$TextBox.Top = $GoButton.Bottom + 5
$TextBox.Width = $Panel.ClientWidth - $TextBox.Left - 5
$TextBox.Height = 150
$TextBox.Enabled = 0
$SaveButton = $Panel.Controls.Add($System.Button())
$SaveButton.Left = 10
$SaveButton.Top = $TextBox.Bottom + 5
$SaveButton.Width = 150
$SaveButton.Text = "3) Save my card..."
$SaveButton.TextAlign = $System.ContentAlignment_MiddleLeft
$SaveButton.Enabled = 0
$SaveButton.Click = "SaveButton_Click($$System.Sender, $$System.EventArgs)"
$OpenFileDialog = $System.OpenFileDialog()
$OpenFileDialog.InitialDirectory = @SCRIPTDIR
$OpenFileDialog.Filter = "Templates (*.crd)|*.crd|All Files (*.*)|*.*"
$SaveFileDialog = $System.SaveFileDialog()
$SaveFileDialog.Filter = "Images (*.jpg)|*.jpg|All Files (*.*)|*.*"
$SaveFileDialog.InitialDirectory = @CURDIR
$Form.Center
$Form.Show
$TextBox.Anchor = 1+4+8
While $Form.Visible
$= Execute($Form.DoEvents)
Loop
Exit 0
Function OpenButton_Click($sender, $e)
If $OpenFileDialog.ShowDialog <> $System.DialogResult_Ok
Return
Endif
$Filename = $OpenFileDialog.FileName
$BaseImage = $System.Bitmap.FromFile($Filename)
$PictureBox.Image = $BaseImage
$TextBox.Text = ""
$TextBox.Text = $TextBox.Text + "John Doe" + @CRLF
$TextBox.Text = $TextBox.Text + "Burbank Town Center" + @CRLF
$TextBox.Text = $TextBox.Text + "201 East Magnolia, Suite 151" + @CRLF
$TextBox.Text = $TextBox.Text + "Burbank, California 91502" + @CRLF
$TextBox.Text = $TextBox.Text + "(818) 566-8556" + @CRLF
$TextBox.Enabled = 1
$SaveButton.Enabled = 1
$GoButton.Enabled = 1
$GoButton.Focus
EndFunction
Function GoButton_Click($sender, $e)
Dim $Image, $Graphics, $Font, $Brush
$Image = $BaseImage.Clone(0,0,$BaseImage.Width, $BaseImage.Height)
$Graphics = $System.Graphics.FromImage($Image)
$Font = $Form.Font
$Brush = $System.SolidBrush($System.Color.White)
$Graphics.DrawString($TextBox.Text, $Font, $Brush, 10, 10)
$PictureBox.Image = $Image
EndFunction
Function SaveButton_Click($sender, $e)
$SaveFileDialog.Filename = GetFreeFileName($SaveFileDialog.InitialDirectory, "Untitled", "jpg")
If $SaveFileDialog.ShowDialog <> $System.DialogResult_Ok
Return
Endif
$Image = $PictureBox.Image
$Image.Save($SaveFileDialog.Filename)
EndFunction
Function ExitMenu_Click($sender, $e)
Quit
EndFunction
Function GetFreeFilename($Dir, $Name, $Ext)
Dim $Free
Dim $Index
Dim $FileName
$Index = 1
Do
$Free = 0
$FileName = $Dir + "\" + $Name + $Index + "." + $Ext
If Not Exist($FileName)
$Free = 1
Endif
$Index = $Index + 1
Until $Free = 1
$GetFreeFilename = $FileName
EndFunction
|
Top
|
|
|
|
#186170 - 2008-03-12 06:36 PM
Re: Easy123 Business Card Maker
[Re: Shawn]
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Here's a version with a little font button on it ...
Break On
$System = CreateObject("Kixforms.System")
$Form = $System.Form()
$Form.Text = "Easy123 Business Card Maker"
$Form.ClientWidth = 640
$Form.ClientHeight = 300
$Form.FontSize = 10
$BaseFont = $Form.Font
$PictureBox = $Form.Controls.Add($System.PictureBox())
$PictureBox.BackColor = $System.Color.AppWorkspace
$PictureBox.Dock = $System.DockStyle_Fill
$PictureBox.BorderStyle = $System.BorderStyle_Fixed3D
$Splitter = $Form.Controls.Add($System.Splitter())
$Splitter.Dock = $System.DockStyle_Left
$Panel = $Form.Controls.Add($System.Panel())
$Panel.Dock = $System.DockStyle_Left
$OpenButton = $Panel.Controls.Add($System.Button())
$OpenButton.Left = 10
$OpenButton.Top = 5
$OpenButton.Width = 150
$OpenButton.Text = "1) Open a template..."
$OpenButton.TextAlign = $System.ContentAlignment_MiddleLeft
$OpenButton.Enabled = 1
$OpenButton.Click = "OpenButton_Click($$System.Sender, $$System.EventArgs)"
$GoButton = $Panel.Controls.Add($System.Button())
$GoButton.Left = 10
$GoButton.Top = $OpenButton.Bottom + 5
$GoButton.Width = 150
$GoButton.Text = "2) Make my card --->"
$GoButton.TextAlign = $System.ContentAlignment_MiddleLeft
$GoButton.Enabled = 0
$GoButton.Click = "GoButton_Click($$System.Sender, $$System.EventArgs)"
$TextBox = $Panel.Controls.Add($System.TextBox())
$TextBox.MultiLine = 1
$TextBox.Left = 10
$TextBox.Top = $GoButton.Bottom + 5
$TextBox.Width = $Panel.ClientWidth - $TextBox.Left - 5
$TextBox.Height = 150
$TextBox.Enabled = 0
$SaveButton = $Panel.Controls.Add($System.Button())
$SaveButton.Left = 10
$SaveButton.Top = $TextBox.Bottom + 5
$SaveButton.Width = 150
$SaveButton.Text = "3) Save my card..."
$SaveButton.TextAlign = $System.ContentAlignment_MiddleLeft
$SaveButton.Enabled = 0
$SaveButton.Click = "SaveButton_Click($$System.Sender, $$System.EventArgs)"
$FontButton = $Panel.Controls.Add($System.Button())
$FontButton.Left = 10
$FontButton.Top = $SaveButton.Bottom + 15
$FontButton.Width = 100
$FontButton.Text = "Font..."
;;$FontButton.TextAlign = $System.ContentAlignment_MiddleLeft
$FontButton.Enabled = 0
$FontButton.Click = "FontButton_Click($$System.Sender, $$System.EventArgs)"
$OpenFileDialog = $System.OpenFileDialog()
$OpenFileDialog.InitialDirectory = @SCRIPTDIR
$OpenFileDialog.Filter = "Templates (*.crd)|*.crd|All Files (*.*)|*.*"
$SaveFileDialog = $System.SaveFileDialog()
$SaveFileDialog.Filter = "Images (*.jpg)|*.jpg|All Files (*.*)|*.*"
$SaveFileDialog.InitialDirectory = @CURDIR
$FontDialog = $System.FontDialog()
$Form.Center
$Form.Show
$TextBox.Anchor = 1+4+8
While $Form.Visible
$= Execute($Form.DoEvents)
Loop
Exit 0
Function OpenButton_Click($sender, $e)
If $OpenFileDialog.ShowDialog <> $System.DialogResult_Ok
Return
Endif
$Filename = $OpenFileDialog.FileName
$BaseImage = $System.Bitmap.FromFile($Filename)
$PictureBox.Image = $BaseImage
$TextBox.Text = ""
$TextBox.Text = $TextBox.Text + "John Doe" + @CRLF
$TextBox.Text = $TextBox.Text + "Burbank Town Center" + @CRLF
$TextBox.Text = $TextBox.Text + "201 East Magnolia, Suite 151" + @CRLF
$TextBox.Text = $TextBox.Text + "Burbank, California 91502" + @CRLF
$TextBox.Text = $TextBox.Text + "(818) 566-8556" + @CRLF
$TextBox.Enabled = 1
$SaveButton.Enabled = 1
$FontButton.Enabled = 1
$GoButton.Enabled = 1
$GoButton.Focus
EndFunction
Function GoButton_Click($sender, $e)
Dim $Image, $Graphics, $Font, $Brush
$Image = $BaseImage.Clone(0,0,$BaseImage.Width, $BaseImage.Height)
$Graphics = $System.Graphics.FromImage($Image)
$Brush = $System.SolidBrush($System.Color.White)
$Graphics.DrawString($TextBox.Text, $BaseFont, $Brush, 10, 10)
$PictureBox.Image = $Image
EndFunction
Function SaveButton_Click($sender, $e)
$SaveFileDialog.Filename = GetFreeFileName($SaveFileDialog.InitialDirectory, "Untitled", "jpg")
If $SaveFileDialog.ShowDialog <> $System.DialogResult_Ok
Return
Endif
$Image = $PictureBox.Image
$Image.Save($SaveFileDialog.Filename)
EndFunction
Function FontButton_Click($sender, $e)
$FontDialog.Font = $BaseFont
If $FontDialog.ShowDialog <> $System.DialogResult_Ok
Return
Endif
$BaseFont = $FontDialog.Font
EndFunction
Function ExitMenu_Click($sender, $e)
Quit
EndFunction
Function GetFreeFilename($Dir, $Name, $Ext)
Dim $Free
Dim $Index
Dim $FileName
$Index = 1
Do
$Free = 0
$FileName = $Dir + "\" + $Name + $Index + "." + $Ext
If Not Exist($FileName)
$Free = 1
Endif
$Index = $Index + 1
Until $Free = 1
$GetFreeFilename = $FileName
EndFunction
|
Top
|
|
|
|
#186190 - 2008-03-12 08:55 PM
Re: Easy123 Business Card Maker
[Re: masken]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
That is the program I was talking about in your other post Masken. But normally used with PHP, but can be used with other tools.
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 980 anonymous users online.
|
|
|