PDA

View Full Version : سوال: جابه جاکردن فرمی که border=none هست



hamed.alinejad
دوشنبه 14 بهمن 1392, 18:25 عصر
سلام دوستای عزیزم خسته نباشید

من یه فرم دارم که border اون none هست
روی اون فرم یه عکس هست میخوای وقتی روی اون عکس کیک کردم و نگه داشت عین فرم های معمولی که میشه جابه جا کرد کاربر بتونه جابه جا کنه ممنون میشم اگه کسی کدش رو واسم بگه

barnamenevisjavan
دوشنبه 14 بهمن 1392, 18:56 عصر
با حذف برخی از خط ها میتونید اون تایتل بار جدید رو هم حذفش کنید

Imports System.Drawing
Imports System.Drawing.Drawing2D
'
'
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 btnClose As System.Windows.Forms.Button
Friend WithEvents t As System.Windows.Forms.Timer
Friend WithEvents cMnu As System.Windows.Forms.ContextMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.btnClose = New System.Windows.Forms.Button()
Me.t = New System.Windows.Forms.Timer(Me.components)
Me.cMnu = New System.Windows.Forms.ContextMenu()
Me.MenuItem1 = New System.Windows.Forms.MenuItem()
Me.MenuItem2 = New System.Windows.Forms.MenuItem()
Me.SuspendLayout()
'
'btnClose
'
Me.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.btnClose.Font = New System.Drawing.Font("Impact", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnClose.Location = New System.Drawing.Point(24, 40)
Me.btnClose.Name = "btnClose"
Me.btnClose.Size = New System.Drawing.Size(192, 24)
Me.btnClose.TabIndex = 0
Me.btnClose.Text = "Close"
'
't
'
Me.t.Enabled = True
Me.t.Interval = 50
'
'cMnu
'
Me.cMnu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.Text = "File"
'
'MenuItem2
'
Me.MenuItem2.Index = 1
Me.MenuItem2.Text = "Subclass to Show"
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.DarkMagenta
Me.ClientSize = New System.Drawing.Size(307, 181)
Me.Controls.Add(Me.btnClose)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.MaximizeBox = False
Me.Name = "frmMain"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n
Me.Text = " Move Form Without Titlebar by Subclassing"
Me.ResumeLayout(False)

End Sub

#End Region
'
'
Dim linearBrush As LinearGradientBrush
Dim f As Font
Dim b As SolidBrush

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'
'
linearBrush = New LinearGradientBrush(New Rectangle(0, 0, Me.Width, 30), Color.DarkCyan, _
Color.Blue, LinearGradientMode.Horizontal)


f = New Font("impact", 10, FontStyle.Regular)

b = New SolidBrush(Color.CadetBlue)

End Sub

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

e.Graphics.FillRectangle(linearBrush, linearBrush.Rectangle)

e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
e.Graphics.DrawString("Move Form without Titlebar by Subclassing", f, b, 1, 5)

End Sub

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click

Me.Close()

End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
'
'The base class should handle the messages.
MyBase.WndProc(m)
'
'Constants used for the window messages.
Const HTCLIENT As Integer = &H1
Const HTCAPTION As Integer = &H2
Const WM_NCHITTEST As Integer = &H84
'
'Simple message intercepting by checking if the mouse cursor is inside the form (Client Portion)
'and windows is hittesting to get the cursor position, then let windows actually believe
'it is actually at the default titlebar of a form.
If m.Result.ToInt32 = HTCLIENT And m.Msg = WM_NCHITTEST Then
'
'Check to see if the cursor/mouse is inside the Y bounds of the custom drawn titlebar
'and change the message to HTCAPTION. Simply remove this If statement if you want the
'user to be able to move the form at any location.
If Me.PointToClient(Cursor.Position).Y <= linearBrush.Rectangle.Bottom Then
'
'Tell Windows its at the Caption (Title area) portion of the Form.
m.Result = New IntPtr(HTCAPTION)

End If

End If

End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
'
'The base class should handle the messages.
MyBase.WndProc(m)
'
'Constants used for the window messages.
Const HTCLIENT As Integer = &H1
Const HTCAPTION As Integer = &H2
Const WM_NCHITTEST As Integer = &H84
'
'Simple message intercepting by checking if the mouse cursor is inside the form (Client Portion)
'and windows is hittesting to get the cursor position, then let windows actually believe
'it is actually at the default titlebar of a form.
If m.Result.ToInt32 = HTCLIENT And m.Msg = WM_NCHITTEST Then
'
'Check to see if the cursor/mouse is inside the Y bounds of the custom drawn titlebar
'and change the message to HTCAPTION. Simply remove this If statement if you want the
'user to be able to move the form at any location.
If Me.PointToClient(Cursor.Position).Y <= linearBrush.Rectangle.Bottom Then
'
'Tell Windows its at the Caption (Title area) portion of the Form.
m.Result = New IntPtr(HTCAPTION)

End If

End If

End Sub
End Class

hamed.alinejad
دوشنبه 14 بهمن 1392, 18:58 عصر
داداش دستت درد نکنه میتونی طرز استفادش رو هم یکم توضیح بدی ؟

یا اگه نمونه آماده هست میتونی بذاری واسه دانلود ؟

barnamenevisjavan
دوشنبه 14 بهمن 1392, 23:26 عصر
یه پروژه جدید باز کن برو تو قسمت کدها همشو پاک کن اینارو همشو کپی کن
اجراش کن

hamed.alinejad
سه شنبه 15 بهمن 1392, 10:12 صبح
دوست عزیز اینکارو کردم ولی خطا داد و اجرا نشد

شاید منظور منو دقیق متوجه نشدید من عکس و یه پروژه تست رو در پست اولم ویرایش کردم گذاشتم اونجا ممنون میشم پروژه ای که خودم گذاشتم رو ببینید و اصلاح کنید

hamed.alinejad
سه شنبه 15 بهمن 1392, 10:21 صبح
یه تاپیک هم دیدم به زبان سی شارپ هست ممنون میشم اینو ویژوال کنید

http://barnamenevis.org/showthread.php?320982-%DA%86%DA%AF%D9%88%D9%86%D9%87-Dock-%D9%81%D8%B1%D9%85%DB%8C-%DA%A9%D9%87-%D8%B1%D9%88%D8%AD%D8%A7%D9%84%D8%AA-None-%D9%87%D8%B3%D8%AA-%D8%B1%D9%88-%D8%A7%DB%8C%D8%AC%D8%A7%D8%AF-%DA%A9%D9%86%DB%8C%D9%85%D8%9F

barnamenevisjavan
سه شنبه 15 بهمن 1392, 11:40 صبح
اینقدر تنبل نباشید من کل کد رو گذاشتم براتون ولی شما حتی نمیتونید کدهارو تشخیص بدید

ilia.rezaee
سه شنبه 15 بهمن 1392, 14:03 عصر
اینقدر تنبل نباشید من کل کد رو گذاشتم براتون ولی شما حتی نمیتونید کدهارو تشخیص بدید
سلام
تنبل؟؟!!:متعجب:این کدها خیلی زیاد بود و سخته فهمیدنش
بفرمایید اینو تبدیل کردم:
دوست من شما باید چهار تا متغییر تعریف کنین به صورت عمومی

Dim ox As Integer, oy As Integer, nx As Integer, ny As Integer
بعدش وقتی که کاربر رو بوردر برنامه شما کلیک کند باید مختصات ماوس در متغییر ها ثبت بشه و شکل ماوس Cursor تغییر کنه البته تو رویداد MouseDown همون Border

If e.Button = MouseButtons.Left Then
Me.ox = e.X
Me.oy = e.Y
Me.Cursor = Cursors.SizeAll
End If
بعد باید وقتی که ماوس حرکت کنه پنجره تغییر لوکیشن بدهد در اینجا باید چک کنیم آیا کلیک ماوس کلیک شده است بعد با استفاده از مختصات قبلی ماوس و مختصات جدید تغییرش میدیم تو رویداد MouseMove :

If e.Button = MouseButtons.Left Then
Me.nx = e.X
Me.ny = e.Y
Me.Left += Me.nx - Me.ox
Me.Top += Me.ny - Me.oy
Else
Me.Cursor = Cursors.[Default]
End If