Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Strict On Public Class Form1 Dim texte As TextBox Dim x, y, diff, dify As Int32 Dim vignette As Integer Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim i As Int32 Panel1.Controls.Clear() y = 0 x = 0 For i = 0 To 9 'création TextBox texte = New TextBox() texte.Multiline = True texte.Width = 100 texte.Height = 100 texte.BorderStyle = BorderStyle.Fixed3D texte.Visible = True texte.Name = "montexte" & i vignette = 90 texte.SetBounds(x, y, vignette, vignette) x += vignette 'vérifier s'il ya suffisamment d'espace dans l'axe x pour ajouter une textBox If x >= Panel1.Width Or (x + vignette) > Panel1.Width Then diff = Panel1.Width - x 'S'il n'y a pas assez d'espace, commencer une nouvelle ligne ci-dessous y += vignette x = 0 End If If ((y + vignette) > Panel1.Height) Then dify = Panel1.Height - y End If 'ajouter une textBox Panel1.Controls.Add(texte) Next i End Sub End Class
Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Me.Width = 280 Me.Height = 300 Me.Location = New Point(100, 100) Form2.Show() End Sub End Class
Option Strict Off Imports System.IO Public Class Form2 Enum FsModifiers None = 0 Alt = 1 Control = 2 Shift = 4 Windows = 8 Alt_Ctrl = 3 Alt_Shift = 5 Alt_Windows = 9 Ctrl_Shift = 6 Ctrl_Windows = 10 Shift_Windows = 12 No_Repeat = 16384 End Enum Declare Auto Function RegisterHotKey Lib "user32.dll" (ByVal handle As IntPtr, ByVal id As Integer, ByVal fsModifier As FsModifiers, ByVal vk As Keys) As Boolean Declare Auto Function UnregisterHotKey Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal id As Integer) As Integer Private Const HOTKEY_ID1 As Integer = 571584 Private Const HOTKEY_ID2 As Integer = 752452 Private Const WM_HOTKEY As Integer = 786 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Select Case m.Msg 'on va tester le message reçu à chaque appel de cette fonction Case WM_HOTKEY 'si il s'agit du message WM_HOTKEY (si l'utilisateur a appuyé sur CTRL + ALT + B) If m.WParam = HOTKEY_ID1 Then 'on cherche quelle hotkey a déclenché l'évènement ' MsgBox("Ctrl + alt + b") selection() ElseIf m.WParam = HOTKEY_ID2 Then ' MsgBox("Ctrl + alt + c") save_texte() End If End Select MyBase.WndProc(m) End Sub Dim texte As TextBox Dim x, y, diff, dify As Int32 Dim vignette As Integer Dim nom As String Dim textesave As String Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing UnregisterHotKey(Me.Handle, HOTKEY_ID1) UnregisterHotKey(Me.Handle, HOTKEY_ID2) End Sub Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load RegisterHotKey(Me.Handle, HOTKEY_ID1, FsModifiers.Alt_Ctrl, Keys.B) RegisterHotKey(Me.Handle, HOTKEY_ID2, FsModifiers.Alt_Ctrl, Keys.C) Me.Location = New Point(100, 100) Me.Width = 280 Me.Height = 300 Me.TransparencyKey = Color.White Me.BackColor = Color.White Me.TopMost = True Dim i As Int32 Panel1.Controls.Clear() y = 0 x = 0 For i = 1 To 9 'création TextBox texte = New TextBox() texte.Multiline = True texte.Width = 100 texte.Height = 100 texte.BackColor = Color.White texte.ForeColor = Color.Red texte.Font = New Font("Tahoma", 20, FontStyle.Bold) texte.BorderStyle = BorderStyle.Fixed3D texte.Visible = True texte.Name = "montexte" & i texte.ShortcutsEnabled = True 'texte.ScrollBars = System.Windows.Forms.ScrollBars.Vertical vignette = 90 texte.SetBounds(x, y, vignette, vignette) x += vignette 'vérifier s'il ya suffisamment d'espace dans l'axe x pour ajouter une textBox If x >= Panel1.Width Or (x + vignette) > Panel1.Width Then diff = Panel1.Width - x 'S'il n'y a pas assez d'espace, commencer une nouvelle ligne ci-dessous y += vignette x = 0 End If If ((y + vignette) > Panel1.Height) Then dify = Panel1.Height - y End If 'ajouter une textBox Panel1.Controls.Add(texte) Next i End Sub Private Sub selection() Dim ctrl As Control For Each ctrl In Panel1.Controls If (ctrl.GetType() Is GetType(TextBox)) Then Dim txt As TextBox = CType(ctrl, TextBox) If txt.Name = "montexte1" Then txt.Focus() End If End If Next End Sub Private Sub save_texte() Dim ctrl As Control For Each ctrl In Panel1.Controls If (ctrl.GetType() Is GetType(TextBox)) Then Dim txt As TextBox = CType(ctrl, TextBox) If txt.Focused = True Then nom = txt.Name textesave = txt.Text If File.Exists(Application.StartupPath & "\" & nom & ".txt") Then Dim contenu As New System.IO.StreamWriter(Application.StartupPath & "\" & nom & ".txt") contenu.Write(textesave) textesave = String.Empty contenu.Close() MessageBox.Show("Fichier enrgistré", "Enregistrement fichier", MessageBoxButtons.OK, MessageBoxIcon.Information) Else Dim mon_fichier As New FileInfo(Application.StartupPath & "\" & nom & ".txt") mon_fichier.Create() MessageBox.Show("Fichier créé", "Création fichier", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End If End If Next End Sub End Class