|
The mistake is in your design combined with not understand how MDI works.
MDI Parent forms have a control on them, automatically, that takes up the entire client area of the form. This control is called the MDIClient (the dark gray area) and it sits docked to all of the free space on the form. It also sits behind all other controls on the form. This control handles rendering and management of all of your MDI Child forms. When you create a child form, it gets shown inside this MDIClient control.
Now, since the MDIClient control sits behind all other controls on the MDI Parent form, this is why you're getting the results you're seeing. The quick solution is simple, don't put controls on the MDI Parent form.
The harder solution is to, in code, find the MDIClient control in the MDI Parent form's Controls container, undock the MDIClent control, move the MDI Parent controls to the edge of the form, then set the Location and Size properties of the MDIClient to somewhere where your MDI Child forms will still be visible and you can still get to the MDI Parent controls.
|
|
|
|
|
I need some help with saving and retrieving images with microsoft sql server.
I have created a form that captures personal information and a picture.
I am having problems with how to saving this data with the picture.
I will also like to display this data at a later time or in another form.
Please help.
|
|
|
|
|
|
hi,
follow step by step
1. first of all i assume PictureBox1 hold the picture data. So use following statement
Dim PictureBox1Data As Byte()<br />
If PictureBox1.Image Is Nothing Then<br />
PictureBox1Data = Nothing<br />
Else<br />
PictureBox1Data = imageToByteArray(PictureBox1.Image)'See below this function<br />
End If
2.Now write the SQL query as following
Dim QueryText As String<br />
Dim QueryValue As String<br />
Dim command As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand()<br />
QueryText = "INSERT INTO Settings(PrintCompany,IsUploadLogo,LogoGraphic )"<br />
QueryValue = "Values(@PrintCompany, @IsUploadLogo,@LogoGraphic)" <br />
command.CommandText = QueryText & QueryValue<br />
3. Supply Value to parameter which is in above query, as following
command.Parameters.Add("@PrintCompany", SqlDbType.TinyInt, 10).Value = True<br />
command.Parameters.Add("@IsUploadLogo", SqlDbType.TinyInt, 10).Value =True<br />
If Not PictureBox1Data Is Nothing Then<br />
command.Parameters.Add("@LogoGraphic", SqlDbType.Image, PictureBox1Data.Length).Value = PictureBox1Data<br />
Else<br />
command.Parameters.Add("@LogoGraphic", SqlDbType.Image, 0).Value = System.DBNull.Value<br />
End If
4. Execute query as following
command.ExecuteNonQuery()
step 1 to 4 read data of picture box,convert them byte array and store in related table.Step 1 use following function to convert an image into byte array
Public Function imageToByteArray(ByVal ImageIn As System.Drawing.Image) As Byte()<br />
Dim ms As MemoryStream = New MemoryStream()<br />
Dim FormatImage1 As Imaging.ImageFormat = ImageIn.RawFormat<br />
ImageIn.Save(ms, FormatImage1)<br />
'ImageIn.Save(ms, Imaging.ImageFormat.Bmp)<br />
Return ms.ToArray()<br />
End Function
5. Now Use following statement to get dataset
str = "select * from Settings"<br />
Dim ds As New DataSet<br />
ds = mdIns.GetResultFromQuery(str)'this function return dataset<br />
6. use dataset record as following
If ds.Tables(0).Rows.Count > 0 Then<br />
chkPrintCompanyName.Checked = CBool(ds.Tables(0).Rows(0).Item(0))<br />
chkLogoGraphic.Checked = CBool(ds.Tables(0).Rows(0).Item(1))<br />
If Not IsDBNull(ds.Tables(0).Rows(0).Item(4)) And Not ds.Tables(0).Rows(0).Item(2) Is Nothing Then<br />
PictureBox1.Image = ByteArrayToimage(ds.Tables(0).Rows(0).Item(2))<br />
End If<br />
<br />
End If
step 6 use following function for convert Byte array to Image
Public Function ByteArrayToimage(ByVal ImageArray As Byte()) As Image<br />
Dim ms As MemoryStream = New MemoryStream(ImageArray)<br />
Dim ReturnImage As Image = Image.FromStream(ms)<br />
Return ReturnImage<br />
End Function
hope this helps
|
|
|
|
|
I have got same issue exactly,
while retrieving image from Database to PitcureBox getting error saying that "Parameters is Not Valid", it is look like there is an issue when save the image and converted to string in DB, hope to have some solutions,
|
|
|
|
|
If I run this code from my computers hard drive, C:\, it detects the networked mapped drive, J:\, just fine:
Private Function FolderExists() As Boolean
Return My.Computer.FileSystem.DirectoryExists("J:\Template_Alpha\")
End Function
' Outputs: True
But when I copy the same VB.NET project to the network mapped J:\ drive, the output changes to False . The project is located in a different folder on the J:\ drive and is not a sub folder of J:\Template_Alpha\.
I'm running VS 2008
Is there some kind of network permissions in Visual Studio I have to set to get this code to work?
-Hazelrah
|
|
|
|
|
Try using System.IO instead of filesystem:
Private Function FolderExists() As Boolean
Return System.IO.Directory.Exists("J:\Template_Alpha\")
End Function
no guarantees though...
My advice is free, and you may get what you paid for.
|
|
|
|
|
Unfortunatly that didn't help. I'm pretty certain those two functions resolve to the same CLR code.
I remember having this problem before and I'm pretty certain it's a security thing, but I can't for the life of me find the settings.
Anyone else have an idea?
-Hazelrah
|
|
|
|
|
Can i expoert my Sqldata to a notepad in comma seperated forms and import the same to sql in vb6
|
|
|
|
|
Yes. Just write some code to do it.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
... and if at all possible, forget vb6 and start using .NET (Visual Studio 2008 Express editions are free for download)
My advice is free, and you may get what you paid for.
|
|
|
|
|
I need a sample code for email attachment
|
|
|
|
|
Good for you. I don't.
Motivation is the key to software development.
|
|
|
|
|
I have some - so do lots of people. Some even share it. Try searching CP or Google.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
mighty_mouse wrote: need a sample code for email attachment
I need a brain. If I only had a brain... Do you think, the wizard of Oz has a brain for me?
|
|
|
|
|
The wizard got an HTTP 404 error when trying to upload it to you.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Error 404 - cranial cavity not found
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Only because I'm feeling helpful today :-
Dim oMail As New System.Net.Mail.MailMessage("senders@emailaddress.com", "reciepients@emailaddress.com")
oMail.Priority = Net.Mail.MailPriority.Normal
oMail.Subject = "My Subject"
oMail.Attachments.Add(New System.Net.Mail.Attachment("C:\My Documents\MyFile.Doc"))
oMail.IsBodyHtml = False
oMail.Body = "Please the file attached."
Dim smtp As New System.Net.Mail.SmtpClient("smtp.mailserver.net")
smtp.Credentials = New System.Net.NetworkCredential("myUserName", "MyPassword")
smtp.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
smtp.Send(oMail)
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Hi Friends,
Actually I want to Do Image Encryption and Image decryption but I really dont have so much concept for that,I have seen the Article Given by sudhakar79 but in that Article I Dont Know where did he got the Encrypted Data or how he did the Encryption.I looking for a Image Encryption and Decryption Program that must include the capability of adding Some Text in that encrypted data and then I can Decrypt That Data......I need Some Basic Details.......Can Any body Help Me Please
|
|
|
|
|
An image is just like any other binary file. Search codeproject for file encryption articles. There are quite a few.
What you are actually talking about doing is steganography.
|
|
|
|
|
Yes Dear Exactly I am talking about steganography where I have to Hide my Text Data behind an Image..........So dear Can you plz Help Me in This Context.......
|
|
|
|
|
I have VB code which gave you way how to Encryption and decryption but I don't know how to upload it into forum
--------------------------------------
Imports System
Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents txtDestinationEncrypt As System.Windows.Forms.TextBox
Friend WithEvents btnEncrypt As System.Windows.Forms.Button
Friend WithEvents txtConPassEncrypt As System.Windows.Forms.TextBox
Friend WithEvents txtPassEncrypt As System.Windows.Forms.TextBox
Friend WithEvents txtFileToEncrypt As System.Windows.Forms.TextBox
Friend WithEvents pbStatus As System.Windows.Forms.ProgressBar
Friend WithEvents txtDestinationDecrypt As System.Windows.Forms.TextBox
Friend WithEvents btnDecrypt As System.Windows.Forms.Button
Friend WithEvents txtConPassDecrypt As System.Windows.Forms.TextBox
Friend WithEvents txtPassDecrypt As System.Windows.Forms.TextBox
Friend WithEvents txtFileToDecrypt As System.Windows.Forms.TextBox
Friend WithEvents btnChangeEncrypt As System.Windows.Forms.Button
Friend WithEvents btnBrowseEncrypt As System.Windows.Forms.Button
Friend WithEvents btnChangeDecrypt As System.Windows.Forms.Button
Friend WithEvents btnBrowseDecrypt As System.Windows.Forms.Button
Friend WithEvents OpenFileDialog As System.Windows.Forms.OpenFileDialog
Friend WithEvents FolderBrowserDialog As System.Windows.Forms.FolderBrowserDialog
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.TabControl1 = New System.Windows.Forms.TabControl
Me.TabPage1 = New System.Windows.Forms.TabPage
Me.btnChangeEncrypt = New System.Windows.Forms.Button
Me.txtDestinationEncrypt = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.btnEncrypt = New System.Windows.Forms.Button
Me.txtConPassEncrypt = New System.Windows.Forms.TextBox
Me.txtPassEncrypt = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.btnBrowseEncrypt = New System.Windows.Forms.Button
Me.txtFileToEncrypt = New System.Windows.Forms.TextBox
Me.TabPage2 = New System.Windows.Forms.TabPage
Me.btnChangeDecrypt = New System.Windows.Forms.Button
Me.txtDestinationDecrypt = New System.Windows.Forms.TextBox
Me.Label5 = New System.Windows.Forms.Label
Me.btnDecrypt = New System.Windows.Forms.Button
Me.txtConPassDecrypt = New System.Windows.Forms.TextBox
Me.txtPassDecrypt = New System.Windows.Forms.TextBox
Me.Label6 = New System.Windows.Forms.Label
Me.Label7 = New System.Windows.Forms.Label
Me.Label8 = New System.Windows.Forms.Label
Me.btnBrowseDecrypt = New System.Windows.Forms.Button
Me.txtFileToDecrypt = New System.Windows.Forms.TextBox
Me.pbStatus = New System.Windows.Forms.ProgressBar
Me.OpenFileDialog = New System.Windows.Forms.OpenFileDialog
Me.FolderBrowserDialog = New System.Windows.Forms.FolderBrowserDialog
Me.TabControl1.SuspendLayout()
Me.TabPage1.SuspendLayout()
Me.TabPage2.SuspendLayout()
Me.SuspendLayout()
'
'TabControl1
'
Me.TabControl1.Controls.Add(Me.TabPage1)
Me.TabControl1.Controls.Add(Me.TabPage2)
Me.TabControl1.Location = New System.Drawing.Point(0, 0)
Me.TabControl1.Name = "TabControl1"
Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(384, 144)
Me.TabControl1.TabIndex = 0
'
'TabPage1
'
Me.TabPage1.BackColor = System.Drawing.SystemColors.Control
Me.TabPage1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.TabPage1.Controls.Add(Me.btnChangeEncrypt)
Me.TabPage1.Controls.Add(Me.txtDestinationEncrypt)
Me.TabPage1.Controls.Add(Me.Label4)
Me.TabPage1.Controls.Add(Me.btnEncrypt)
Me.TabPage1.Controls.Add(Me.txtConPassEncrypt)
Me.TabPage1.Controls.Add(Me.txtPassEncrypt)
Me.TabPage1.Controls.Add(Me.Label1)
Me.TabPage1.Controls.Add(Me.Label3)
Me.TabPage1.Controls.Add(Me.Label2)
Me.TabPage1.Controls.Add(Me.btnBrowseEncrypt)
Me.TabPage1.Controls.Add(Me.txtFileToEncrypt)
Me.TabPage1.Location = New System.Drawing.Point(4, 22)
Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Size = New System.Drawing.Size(376, 118)
Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "Encrypt File"
'
'btnChangeEncrypt
'
Me.btnChangeEncrypt.Enabled = False
Me.btnChangeEncrypt.Location = New System.Drawing.Point(296, 32)
Me.btnChangeEncrypt.Name = "btnChangeEncrypt"
Me.btnChangeEncrypt.Size = New System.Drawing.Size(72, 21)
Me.btnChangeEncrypt.TabIndex = 11
Me.btnChangeEncrypt.Text = "Change"
'
'txtDestinationEncrypt
'
Me.txtDestinationEncrypt.Location = New System.Drawing.Point(104, 32)
Me.txtDestinationEncrypt.Name = "txtDestinationEncrypt"
Me.txtDestinationEncrypt.ReadOnly = True
Me.txtDestinationEncrypt.Size = New System.Drawing.Size(184, 20)
Me.txtDestinationEncrypt.TabIndex = 10
Me.txtDestinationEncrypt.Text = ""
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(8, 32)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(88, 16)
Me.Label4.TabIndex = 9
Me.Label4.Text = "File destination:"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btnEncrypt
'
Me.btnEncrypt.Enabled = False
Me.btnEncrypt.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnEncrypt.Location = New System.Drawing.Point(296, 72)
Me.btnEncrypt.Name = "btnEncrypt"
Me.btnEncrypt.Size = New System.Drawing.Size(72, 32)
Me.btnEncrypt.TabIndex = 8
Me.btnEncrypt.Text = "Encrypt"
'
'txtConPassEncrypt
'
Me.txtConPassEncrypt.Location = New System.Drawing.Point(104, 88)
Me.txtConPassEncrypt.Name = "txtConPassEncrypt"
Me.txtConPassEncrypt.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtConPassEncrypt.Size = New System.Drawing.Size(184, 20)
Me.txtConPassEncrypt.TabIndex = 7
Me.txtConPassEncrypt.Text = ""
'
'txtPassEncrypt
'
Me.txtPassEncrypt.Location = New System.Drawing.Point(104, 64)
Me.txtPassEncrypt.Name = "txtPassEncrypt"
Me.txtPassEncrypt.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtPassEncrypt.Size = New System.Drawing.Size(184, 20)
Me.txtPassEncrypt.TabIndex = 6
Me.txtPassEncrypt.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 16)
Me.Label1.TabIndex = 5
Me.Label1.Text = "File to encrypt:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(-8, 88)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(104, 16)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Confirm password:"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(88, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Type password:"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btnBrowseEncrypt
'
Me.btnBrowseEncrypt.Location = New System.Drawing.Point(296, 8)
Me.btnBrowseEncrypt.Name = "btnBrowseEncrypt"
Me.btnBrowseEncrypt.Size = New System.Drawing.Size(72, 21)
Me.btnBrowseEncrypt.TabIndex = 2
Me.btnBrowseEncrypt.Text = "Browse"
'
'txtFileToEncrypt
'
Me.txtFileToEncrypt.Location = New System.Drawing.Point(104, 8)
Me.txtFileToEncrypt.Name = "txtFileToEncrypt"
Me.txtFileToEncrypt.ReadOnly = True
Me.txtFileToEncrypt.Size = New System.Drawing.Size(184, 20)
Me.txtFileToEncrypt.TabIndex = 1
Me.txtFileToEncrypt.Text = "Click Browse to load file."
'
'TabPage2
'
Me.TabPage2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.TabPage2.Controls.Add(Me.btnChangeDecrypt)
Me.TabPage2.Controls.Add(Me.txtDestinationDecrypt)
Me.TabPage2.Controls.Add(Me.Label5)
Me.TabPage2.Controls.Add(Me.btnDecrypt)
Me.TabPage2.Controls.Add(Me.txtConPassDecrypt)
Me.TabPage2.Controls.Add(Me.txtPassDecrypt)
Me.TabPage2.Controls.Add(Me.Label6)
Me.TabPage2.Controls.Add(Me.Label7)
Me.TabPage2.Controls.Add(Me.Label8)
Me.TabPage2.Controls.Add(Me.btnBrowseDecrypt)
Me.TabPage2.Controls.Add(Me.txtFileToDecrypt)
Me.TabPage2.Location = New System.Drawing.Point(4, 22)
Me.TabPage2.Name = "TabPage2"
Me.TabPage2.Size = New System.Drawing.Size(376, 118)
Me.TabPage2.TabIndex = 1
Me.TabPage2.Text = "Decrypt File"
'
'btnChangeDecrypt
'
Me.btnChangeDecrypt.Enabled = False
Me.btnChangeDecrypt.Location = New System.Drawing.Point(296, 32)
Me.btnChangeDecrypt.Name = "btnChangeDecrypt"
Me.btnChangeDecrypt.Size = New System.Drawing.Size(72, 21)
Me.btnChangeDecrypt.TabIndex = 22
Me.btnChangeDecrypt.Text = "Change"
'
'txtDestinationDecrypt
'
Me.txtDestinationDecrypt.Location = New System.Drawing.Point(104, 32)
Me.txtDestinationDecrypt.Name = "txtDestinationDecrypt"
Me.txtDestinationDecrypt.ReadOnly = True
Me.txtDestinationDecrypt.Size = New System.Drawing.Size(184, 20)
Me.txtDestinationDecrypt.TabIndex = 21
Me.txtDestinationDecrypt.Text = ""
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(8, 32)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(88, 16)
Me.Label5.TabIndex = 20
Me.Label5.Text = "File destination:"
Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btnDecrypt
'
Me.btnDecrypt.Enabled = False
Me.btnDecrypt.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnDecrypt.Location = New System.Drawing.Point(296, 72)
Me.btnDecrypt.Name = "btnDecrypt"
Me.btnDecrypt.Size = New System.Drawing.Size(72, 32)
Me.btnDecrypt.TabIndex = 19
Me.btnDecrypt.Text = "Decrypt"
'
'txtConPassDecrypt
'
Me.txtConPassDecrypt.Location = New System.Drawing.Point(104, 88)
Me.txtConPassDecrypt.Name = "txtConPassDecrypt"
Me.txtConPassDecrypt.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtConPassDecrypt.Size = New System.Drawing.Size(184, 20)
Me.txtConPassDecrypt.TabIndex = 18
Me.txtConPassDecrypt.Text = ""
'
'txtPassDecrypt
'
Me.txtPassDecrypt.Location = New System.Drawing.Point(104, 64)
Me.txtPassDecrypt.Name = "txtPassDecrypt"
Me.txtPassDecrypt.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtPassDecrypt.Size = New System.Drawing.Size(184, 20)
Me.txtPassDecrypt.TabIndex = 17
Me.txtPassDecrypt.Text = ""
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(16, 8)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(80, 16)
Me.Label6.TabIndex = 16
Me.Label6.Text = "File to decrypt:"
Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(-8, 88)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(104, 16)
Me.Label7.TabIndex = 15
Me.Label7.Text = "Confirm password:"
Me.Label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(8, 64)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(88, 16)
Me.Label8.TabIndex = 14
Me.Label8.Text = "Type password:"
Me.Label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btnBrowseDecrypt
'
Me.btnBrowseDecrypt.Location = New System.Drawing.Point(296, 8)
Me.btnBrowseDecrypt.Name = "btnBrowseDecrypt"
Me.btnBrowseDecrypt.Size = New System.Drawing.Size(72, 21)
Me.btnBrowseDecrypt.TabIndex = 13
Me.btnBrowseDecrypt.Text = "Browse"
'
'txtFileToDecrypt
'
Me.txtFileToDecrypt.Location = New System.Drawing.Point(104, 8)
Me.txtFileToDecrypt.Name = "txtFileToDecrypt"
Me.txtFileToDecrypt.ReadOnly = True
Me.txtFileToDecrypt.Size = New System.Drawing.Size(184, 20)
Me.txtFileToDecrypt.TabIndex = 12
Me.txtFileToDecrypt.Text = "Click Browse to load file."
'
'pbStatus
'
Me.pbStatus.Location = New System.Drawing.Point(0, 144)
Me.pbStatus.Name = "pbStatus"
Me.pbStatus.Size = New System.Drawing.Size(384, 16)
Me.pbStatus.TabIndex = 1
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(382, 156)
Me.Controls.Add(Me.pbStatus)
Me.Controls.Add(Me.TabControl1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.Name = "frmMain"
Me.Text = "Encrypt / Decrypt File (Using Rijndael)"
Me.TabControl1.ResumeLayout(False)
Me.TabPage1.ResumeLayout(False)
Me.TabPage2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
#Region "1. Global Variables "
'*************************
'** Global Variables
'*************************
Dim strFileToEncrypt As String
Dim strFileToDecrypt As String
Dim strOutputEncrypt As String
Dim strOutputDecrypt As String
Dim fsInput As System.IO.FileStream
Dim fsOutput As System.IO.FileStream
#End Region
#Region "2. Create A Key "
'*************************
'** Create A Key
'*************************
Private Function CreateKey(ByVal strPassword As String) As Byte()
'Convert strPassword to an array and store in chrData.
Dim chrData() As Char = strPassword.ToCharArray
'Use intLength to get strPassword size.
Dim intLength As Integer = chrData.GetUpperBound(0)
'Declare bytDataToHash and make it the same size as chrData.
Dim bytDataToHash(intLength) As Byte
'Use For Next to convert and store chrData into bytDataToHash.
For i As Integer = 0 To chrData.GetUpperBound(0)
bytDataToHash(i) = CByte(Asc(chrData(i)))
Next
'Declare what hash to use.
Dim SHA512 As New System.Security.Cryptography.SHA512Managed
'Declare bytResult, Hash bytDataToHash and store it in bytResult.
Dim bytResult As Byte() = SHA512.ComputeHash(bytDataToHash)
'Declare bytKey(31). It will hold 256 bits.
Dim bytKey(31) As Byte
'Use For Next to put a specific size (256 bits) of
'bytResult into bytKey. The 0 To 31 will put the first 256 bits
'of 512 bits into bytKey.
For i As Integer = 0 To 31
bytKey(i) = bytResult(i)
Next
Return bytKey 'Return the key.
End Function
#End Region
#Region "3. Create An IV "
'*************************
'** Create An IV
'*************************
Private Function CreateIV(ByVal strPassword As String) As Byte()
'Convert strPassword to an array and store in chrData.
Dim chrData() As Char = strPassword.ToCharArray
'Use intLength to get strPassword size.
Dim intLength As Integer = chrData.GetUpperBound(0)
'Declare bytDataToHash and make it the same size as chrData.
Dim bytDataToHash(intLength) As Byte
'Use For Next to convert and store chrData into bytDataToHash.
For i As Integer = 0 To chrData.GetUpperBound(0)
bytDataToHash(i) = CByte(Asc(chrData(i)))
Next
'Declare what hash to use.
Dim SHA512 As New System.Security.Cryptography.SHA512Managed
'Declare bytResult, Hash bytDataToHash and store it in bytResult.
Dim bytResult As Byte() = SHA512.ComputeHash(bytDataToHash)
'Declare bytIV(15). It will hold 128 bits.
Dim bytIV(15) As Byte
'Use For Next to put a specific size (128 bits) of
'bytResult into bytIV. The 0 To 30 for bytKey used the first 256 bits.
'of the hashed password. The 32 To 47 will put the next 128 bits into bytIV.
For i As Integer = 32 To 47
bytIV(i - 32) = bytResult(i)
Next
Return bytIV 'return the IV
End Function
#End Region
#Region "4. Encrypt / Decrypt File "
'****************************
'** Encrypt/Decrypt File
'****************************
Private Enum CryptoAction
'Define the enumeration for CryptoAction.
ActionEncrypt = 1
ActionDecrypt = 2
End Enum
Private Sub EncryptOrDecryptFile(ByVal strInputFile As String, _
ByVal strOutputFile As String, _
ByVal bytKey() As Byte, _
ByVal bytIV() As Byte, _
ByVal Direction As CryptoAction)
Try 'In case of errors.
'Setup file streams to handle input and output.
fsInput = New System.IO.FileStream(strInputFile, FileMode.Open, _
FileAccess.Read)
fsOutput = New System.IO.FileStream(strOutputFile, FileMode.OpenOrCreate, _
FileAccess.Write)
fsOutput.SetLength(0) 'make sure fsOutput is empty
'Declare variables for encrypt/decrypt process.
Dim bytBuffer(4096) As Byte 'holds a block of bytes for processing
Dim lngBytesProcessed As Long = 0 'running count of bytes processed
Dim lngFileLength As Long = fsInput.Length 'the input file's length
Dim intBytesInCurrentBlock As Integer 'current bytes being processed
Dim csCryptoStream As CryptoStream
'Declare your CryptoServiceProvider.
Dim cspRijndael As New System.Security.Cryptography.RijndaelManaged
'Setup Progress Bar
pbStatus.Value = 0
pbStatus.Maximum = 100
'Determine if ecryption or decryption and setup CryptoStream.
Select Case Direction
Case CryptoAction.ActionEncrypt
csCryptoStream = New CryptoStream(fsOutput, _
cspRijndael.CreateEncryptor(bytKey, bytIV), _
CryptoStreamMode.Write)
Case CryptoAction.ActionDecrypt
csCryptoStream = New CryptoStream(fsOutput, _
cspRijndael.CreateDecryptor(bytKey, bytIV), _
CryptoStreamMode.Write)
End Select
'Use While to loop until all of the file is processed.
While lngBytesProcessed < lngFileLength
'Read file with the input filestream.
intBytesInCurrentBlock = fsInput.Read(bytBuffer, 0, 4096)
'Write output file with the cryptostream.
csCryptoStream.Write(bytBuffer, 0, intBytesInCurrentBlock)
'Update lngBytesProcessed
lngBytesProcessed = lngBytesProcessed + CLng(intBytesInCurrentBlock)
'Update Progress Bar
pbStatus.Value = CInt((lngBytesProcessed / lngFileLength) * 100)
End While
'Close FileStreams and CryptoStream.
csCryptoStream.Close()
fsInput.Close()
fsOutput.Close()
'If encrypting then delete the original unencrypted file.
If Direction = CryptoAction.ActionEncrypt Then
Dim fileOriginal As New FileInfo(strFileToEncrypt)
fileOriginal.Delete()
End If
'If decrypting then delete the encrypted file.
If Direction = CryptoAction.ActionDecrypt Then
Dim fileEncrypted As New FileInfo(strFileToDecrypt)
fileEncrypted.Delete()
End If
'Update the user when the file is done.
Dim Wrap As String = Chr(13) + Chr(10)
If Direction = CryptoAction.ActionEncrypt Then
MsgBox("Encryption Complete" + Wrap + Wrap + _
"Total bytes processed = " + _
lngBytesProcessed.ToString, _
MsgBoxStyle.Information, "Done")
'Update the progress bar and textboxes.
pbStatus.Value = 0
txtFileToEncrypt.Text = "Click Browse to load file."
txtPassEncrypt.Text = ""
txtConPassEncrypt.Text = ""
txtDestinationEncrypt.Text = ""
btnChangeEncrypt.Enabled = False
btnEncrypt.Enabled = False
Else
'Update the user when the file is done.
MsgBox("Decryption Complete" + Wrap + Wrap + _
"Total bytes processed = " + _
lngBytesProcessed.ToString, _
MsgBoxStyle.Information, "Done")
'Update the progress bar and textboxes.
pbStatus.Value = 0
txtFileToDecrypt.Text = "Click Browse to load file."
txtPassDecrypt.Text = ""
txtConPassDecrypt.Text = ""
txtDestinationDecrypt.Text = ""
btnChangeDecrypt.Enabled = False
btnDecrypt.Enabled = False
End If
'Catch file not found error.
Catch When Err.Number = 53 'if file not found
MsgBox("Please check to make sure the path and filename" + _
"are correct and if the file exists.", _
MsgBoxStyle.Exclamation, "Invalid Path or Filename")
'Catch all other errors. And delete partial files.
Catch
fsInput.Close()
fsOutput.Close()
If Direction = CryptoAction.ActionDecrypt Then
Dim fileDelete As New FileInfo(txtDestinationDecrypt.Text)
fileDelete.Delete()
pbStatus.Value = 0
txtPassDecrypt.Text = ""
txtConPassDecrypt.Text = ""
MsgBox("Please check to make sure that you entered the correct" + _
"password.", MsgBoxStyle.Exclamation, "Invalid Password")
Else
Dim fileDelete As New FileInfo(txtDestinationEncrypt.Text)
fileDelete.Delete()
pbStatus.Value = 0
txtPassEncrypt.Text = ""
txtConPassEncrypt.Text = ""
MsgBox("This file cannot be encrypted.", _
MsgBoxStyle.Exclamation, "Invalid File")
End If
End Try
End Sub
#End Region
#Region "5. Browse / Change Button "
'******************************
'** Browse/Change Buttons
'******************************
Private Sub btnBrowseEncrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnBrowseEncrypt.Click
'Setup the open dialog.
OpenFileDialog.FileName = ""
OpenFileDialog.Title = "Choose a file to encrypt"
OpenFileDialog.InitialDirectory = "C:\"
OpenFileDialog.Filter = "All Files (*.*) | *.*"
'Find out if the user chose a file.
If OpenFileDialog.ShowDialog = DialogResult.OK Then
strFileToEncrypt = OpenFileDialog.FileName
txtFileToEncrypt.Text = strFileToEncrypt
Dim iPosition As Integer = 0
Dim i As Integer = 0
'Get the position of the last "\" in the OpenFileDialog.FileName path.
'-1 is when the character your searching for is not there.
'IndexOf searches from left to right.
While strFileToEncrypt.IndexOf("\"c, i) <> -1
iPosition = strFileToEncrypt.IndexOf("\"c, i)
i = iPosition + 1
End While
'Assign strOutputFile to the position after the last "\" in the path.
'This position is the beginning of the file name.
strOutputEncrypt = strFileToEncrypt.Substring(iPosition + 1)
'Assign S the entire path, ending at the last "\".
Dim S As String = strFileToEncrypt.Substring(0, iPosition + 1)
'Replace the "." in the file extension with "_".
strOutputEncrypt = strOutputEncrypt.Replace("."c, "_"c)
'The final file name. XXXXX.encrypt
txtDestinationEncrypt.Text = S + strOutputEncrypt + ".encrypt"
'Update buttons.
btnEncrypt.Enabled = True
btnChangeEncrypt.Enabled = True
End If
End Sub
Private Sub btnBrowseDecrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnBrowseDecrypt.Click
'Setup the open dialog.
OpenFileDialog.FileName = ""
OpenFileDialog.Title = "Choose a file to decrypt"
OpenFileDialog.InitialDirectory = "C:\"
OpenFileDialog.Filter = "Encrypted Files (*.encrypt) | *.encrypt"
'Find out if the user chose a file.
If OpenFileDialog.ShowDialog = DialogResult.OK Then
strFileToDecrypt = OpenFileDialog.FileName
txtFileToDecrypt.Text = strFileToDecrypt
Dim iPosition As Integer = 0
Dim i As Integer = 0
'Get the position of the last "\" in the OpenFileDialog.FileName path.
'-1 is when the character your searching for is not there.
'IndexOf searches from left to right.
While strFileToDecrypt.IndexOf("\"c, i) <> -1
iPosition = strFileToDecrypt.IndexOf("\"c, i)
i = iPosition + 1
End While
'strOutputFile = the file path minus the last 8 characters (.encrypt)
strOutputDecrypt = strFileToDecrypt.Substring(0, strFileToDecrypt.Length - 8)
'Assign S the entire path, ending at the last "\".
Dim S As String = strFileToDecrypt.Substring(0, iPosition + 1)
'Assign strOutputFile to the position after the last "\" in the path.
strOutputDecrypt = strOutputDecrypt.Substring((iPosition + 1))
'Replace "_" with "."
txtDestinationDecrypt.Text = S + strOutputDecrypt.Replace("_"c, "."c)
'Update buttons
btnDecrypt.Enabled = True
btnChangeDecrypt.Enabled = True
End If
End Sub
Private Sub btnChangeEncrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnChangeEncrypt.Click
'Setup up folder browser.
FolderBrowserDialog.Description = "Select a folder to place the encrypted file in."
'If the user selected a folder assign the path to txtDestinationEncrypt.
If FolderBrowserDialog.ShowDialog = DialogResult.OK Then
txtDestinationEncrypt.Text = FolderBrowserDialog.SelectedPath + _
"\" + strOutputEncrypt + ".encrypt"
End If
End Sub
Private Sub btnChangeDecrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnChangeDecrypt.Click
'Setup up folder browser.
FolderBrowserDialog.Description = "Select a folder for to place the decrypted file in."
'If the user selected a folder assign the path to txtDestinationDecrypt.
If FolderBrowserDialog.ShowDialog = DialogResult.OK Then
txtDestinationDecrypt.Text = FolderBrowserDialog.SelectedPath + _
"\" + strOutputDecrypt.Replace("_"c, "."c)
End If
End Sub
#End Region
#Region "6. Encrypt / Decrypt Buttons "
'******************************
'** Encrypt/Decrypt Buttons
'******************************
Private Sub btnEncrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnEncrypt.Click
'Make sure the password is correct.
If txtConPassEncrypt.Text = txtPassEncrypt.Text Then
'Declare variables for the key and iv.
'The key needs to hold 256 bits and the iv 128 bits.
Dim bytKey As Byte()
Dim bytIV As Byte()
'Send the password to the CreateKey function.
bytKey = CreateKey(txtPassEncrypt.Text)
'Send the password to the CreateIV function.
bytIV = CreateIV(txtPassEncrypt.Text)
'Start the encryption.
EncryptOrDecryptFile(strFileToEncrypt, txtDestinationEncrypt.Text, _
bytKey, bytIV, CryptoAction.ActionEncrypt)
Else
MsgBox("Please re-enter your password.", MsgBoxStyle.Exclamation)
txtPassEncrypt.Text = ""
txtConPassEncrypt.Text = ""
End If
End Sub
Private Sub btnDecrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnDecrypt.Click
'Make sure the password is correct.
If txtConPassDecrypt.Text = txtPassDecrypt.Text Then
'Declare variables for the key and iv.
'The key needs to hold 256 bits and the iv 128 bits.
Dim bytKey As Byte()
Dim bytIV As Byte()
'Send the password to the CreateKey function.
bytKey = CreateKey(txtPassDecrypt.Text)
'Send the password to the CreateIV function.
bytIV = CreateIV(txtPassDecrypt.Text)
'Start the decryption.
EncryptOrDecryptFile(strFileToDecrypt, txtDestinationDecrypt.Text, _
bytKey, bytIV, CryptoAction.ActionDecrypt)
Else
MsgBox("Please re-enter your password.", MsgBoxStyle.Exclamation)
txtPassDecrypt.Text = ""
txtConPassDecrypt.Text = ""
End If
End Sub
#End Region
End Class
----------
----------
This will appear at the end of articles you submit to the Code Project
|
|
|
|
|
If you post code, you should only post the code that is relevant to the question, not the entire project. About 80% of the code you posted is auto-generated and/or UI related, so it could just have been left out.
For code longer than a few lines you should use a code block, so that it doesn't lose the formatting.
And go into your settings and change your signature, or at least remove the default "This will appear at the end of articles you submit to the Code Project" text.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi Dear,
Thanks Dear for your help but dear Actually I am Looking for steganography which means I have to hide my text data behind An image and then Retrieve That Data from the image......the Example you gave me Was difficult To understand for me...........Please can you help me more......
|
|
|
|
|
hi i have an apllication build ( with help !! much help from japarbz )
that opens links like :
http://www.google/userid=1
then http://www.google/userid=2
and so further ..
its an dynamic hyperlink with vazriable i
but now , its a difficult part ( i think)
first
a link has to open ( with the application)
so : http://www.google/userid=1
then , a button on that page has to be clicked
then the page goes like ; http://www.google/userid=1/completed ( example)
then yes , : http://www.google/userid=2 has to open
again , a button on that page has to be clicked ( the same button , same place , so maybe a can use an auto mouse clicker) ?
but i cant take the final url of example -> http://www.google/userid=1/completed cause it wont work so i have to use something like an auto mouseclicker
someone knows how to change the source that i dont have to use an extern auto mouse clicker ?
or someone another idea
here is the source of the appl that i have now ;
Option Explicit
Dim i As Integer
Dim j As Integer
Dim t As Integer
Dim SaveStr As String
Private Sub Command1_Click()
Dim msg As String
msg = InputBox("How many times want to repeat ?", "repeat", 0)
If IsNull(msg) = False And IsNumeric(msg) = True Then
t = CInt(msg)
Else
Timer1.Enabled = False
End If
Timer1.Enabled = True
SaveStr = Text1.Text
End Sub
Private Sub Form_Load()
i = 1
Timer1.Interval = 100
Timer1.Enabled = False
End Sub
Private Sub Form_Resize()
Text1.Width = Me.Width
WebBrowser1.Width = Me.Width
WebBrowser1.Height = Me.Height
Command1.Left = Me.Width - Command1.Width
End Sub
Private Sub Timer1_Timer()
If WebBrowser1.Busy = False Then
WebBrowser1.Navigate SaveStr + CStr(i)
Text1.Text = SaveStr + CStr(i)
i = i + 1
If i = t + 1 Then
Timer1.Enabled = False
Text1.Text = vbNullString
t = 0
i = 1
End If
End If
End Sub
|
|
|
|
|