2012-05-07 2 views
1

Из динамической формы, которую я добавил. Я понял, что не могу получить анимацию gif для работы в фоновом режиме. Поэтому я подумал, что я попытаюсь включить изображение в динамическую форму, но это не работает, поэтому я здесь.VB.NET Move Dynamic Borderless Form через PictureBox

Итак, на моей основной форме (Form1) у меня есть 2 кнопки, openfiledialog и картинка. Когда вы нажимаете кнопку1, вы просматриваете изображение, которое будет отображаться в окне изображения, и когда вы нажимаете кнопку2, как вы можете видеть из приведенного ниже кода. Он откроет новую форму, но я хочу, чтобы изображение отображалось по всей форме, но также воспроизводило анимацию gif, которую я выбрал из своей основной формы через Form1, на динамически вложенную, но в картинную панель. Теперь я не могу использовать его как BackgroundImage, поэтому я использую его как изображение, но теперь проблема заключается в том, что я не могу перемещать каждую форму без полей, и я тоже не могу ее закрыть.

В любом случае вот мой код.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
    WidgetForm = New Form() 
    WidgetForm.ShowInTaskbar = False 
    WidgetForm.TopMost = True 
    WidgetForm.FormBorderStyle = Windows.Forms.FormBorderStyle.None 
    WidgetForm.ContextMenuStrip = ContextMenuStrip2 
    WidgetForm.Show() 

    Dim WidgetBG As PictureBox = New PictureBox() 
    sizew = Me.TextBox1.Text 
    sizey = Me.TextBox2.Text 
    WidgetBG.Size = New System.Drawing.Size(sizew, sizey) 
    WidgetBG.Image = Image.FromFile(Me.OpenFileDialog1.FileName) 
    WidgetBG.Location = New System.Drawing.Point(0, 0) 
    WidgetBG.Visible = True 
    WidgetForm.Controls.Add(WidgetBG) 

    opac = Me.TextBox3.Text 
    WidgetForm.Opacity = opac 
    WidgetForm.Size = New System.Drawing.Size(sizew, sizey) 

    'Add the event here 
    AddHandler WidgetBG.MouseDown, AddressOf WidgetBG_MouseDown 
    AddHandler WidgetBG.MouseMove, AddressOf WidgetBG_MouseMove 
    AddHandler WidgetBG.MouseUp, AddressOf WidgetBG_MouseUp 
    AddHandler WidgetBG.DoubleClick, AddressOf WidgetBG_DoubleClick 
End Sub 

Private Sub WidgetBG_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 
    If e.Button = Windows.Forms.MouseButtons.Left Then 
     drag = True 
     mousex = Windows.Forms.Cursor.Position.X - CType(sender, Form).Left 
     mousey = Windows.Forms.Cursor.Position.Y - CType(sender, Form).Top 
    End If 

    Timer1.Enabled = True 
    Timer1.Interval = 2500 
End Sub 

Private Sub WidgetBG_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 
    If drag Then 
     CType(sender, Form).Top = Windows.Forms.Cursor.Position.Y - mousey 
     CType(sender, Form).Left = Windows.Forms.Cursor.Position.X - mousex 
    End If 
End Sub 

Private Sub WidgetBG_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 
    Timer1.Enabled = False 
    drag = False 
End Sub 

Private Sub WidgetBG_DoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 
    CType(sender, Form).Close() 
End Sub 

Любая помощь была бы принята с благодарностью.

+0

Вы уже знаете, что BackgroundImage не анимировать. Поэтому вместо этого назначьте WidgetBG.Image. –

+0

Код обновлен! Теперь моя проблема в том, что я не могу переместить каждую форму без полей. Вы знаете, как решить эту проблему? –

+0

Ну, конечно, у него нет рамки или заголовка. Так что не делайте его без полей. http://stackoverflow.com/a/3102238/17034 –

ответ

1

Это потому, что вы обрабатывать событие из вашего PictureBox не самой формы, так что вы можете изменить обработчик события, как показано ниже

Private Sub WidgetBG_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 
    If e.Button = Windows.Forms.MouseButtons.Left Then 
     drag = True 

     'Use FindForm() here to get your parent form 
     'You can also use CType(sender, PictureBox).Parent.Left which makes more sense 
     mousex = Windows.Forms.Cursor.Position.X - CType(sender, PictureBox).FindForm().Left 
     mousey = Windows.Forms.Cursor.Position.Y - CType(sender, PictureBox).FindForm().Top 
    End If 

    Timer1.Enabled = True 
    Timer1.Interval = 2500 
End Sub 

Private Sub WidgetBG_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 
    If drag Then 
     CType(sender, PictureBox).FindForm().Top = Windows.Forms.Cursor.Position.Y - mousey 
     CType(sender, PictureBox).FindForm().Left = Windows.Forms.Cursor.Position.X - mousex 
    End If 
End Sub 

Private Sub WidgetBG_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 
    Timer1.Enabled = False 
    drag = False 
End Sub 

Private Sub WidgetBG_DoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 
    CType(sender, PictureBox).FindForm().Close() 
End Sub 
+0

Он работал прилично, пока gif не вернулся к кадру 1, и пока я его не переместил. Когда я получаю следующую ошибку: http://img32.imageshack.us/img32/3042/errorzm.png Вы можете загрузить проект и исходный код через DeviantART. Конечно, с проблемой gif я убедился, что при отпускании отключить его до тех пор, пока эта ошибка не будет решена. http://mikethedj4.deviantart.com/art/WidgetArea-Use-Images-On-Your-HD-As-A-Widget-300769639 –