الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة في التحويل من اليسار لليمين في Change Color Tabpage In Tabcontrol

بدأه mohammed nafa في 1 يناير 2009 · 4 رد · 844 مشاهدة · في Microsoft Visual Basic.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

اخوه الأعزاء

السلام عليكم ورحنة الله وبركاته

الحمد لله استطعت بعد بحث مضني التوصل الى طريقة تلون التاب بيج النشطة ولكن المشكلة أن التاب كنترول لديها صفة التحول من اليسار الى اليمين كون البرنامج مصمم باللغة العربية مما ادى الى انعكاس في كتابة عنوان التاب أرجو المساعدة ان أمكن

مرفق الكود المستعمل :

[CODE]'  In the Form Load event, include this code:
 TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed
'  Obviously change the name of the control if different;-}

'  Then insert this code block on the form:
 Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
		Dim g As Graphics = e.Graphics
		Dim f As Font = New Font(e.Font, FontStyle.Bold)
		Dim b As New SolidBrush(Color.LightBlue)
		g.FillRectangle(b, e.Bounds)
		If e.Index = Me.TabControl1.SelectedIndex Then
			b.Color = Color.Blue
			g.DrawString(Me.TabControl1.TabPages(e.Index).Text, f, b, e.Bounds.X + 2, e.Bounds.Y + 2)
		Else
			b.Color = Color.Black
			g.DrawString(Me.TabControl1.TabPages(e.Index).Text, e.Font, b, e.Bounds.X + 2, e.Bounds.Y + 2)
		End If
		b.Dispose()
		f.Dispose()
	End Sub
#2

بسم الله الرحمن الرحيم

اخوه الأعزاء

السلام عليكم ورحنة الله وبركاته

الإخوة الأعزاء أرجو ممن اتعم الله عليهم بالعلم يتصدقوا علينا مما انعم الله عليهم

وشكرا

م.محمد

#3

أخي الفاضل

اولا TabControl يعتبر كونترول مركب

لتوضيح ذلك

tabPage ----- Inherits -------- From Panel

ثم تم إضافتها الي كونترول أخر فاصبح لدينا Tabcontrol

وبالتالي ان استخدام الحدث DrawItem لن يفي بالغرض تماما فالهدف منه هو تلوين ورسم TabPages الموجوده في Tabcontrol

وهناك events أو أحداث تخص Tabcontrol لا يمكن الوصول اليها الا عن طريق الوراثة

لكي يتم التعديل في خصائئصها بالكامل

وتلاحظ اخي الفاضل ان TabPags تمتكلك خاصية اليمين الي اليسار وأيضا TabControl يمتلك نفس الخواص

وعند استخدامك الكود TabDrawMode.OwnerDrawFixed

بالتالي انت قمت بتغيير اشياء كثيرة منها مثلا انك قمت بإلغاء visualstyles

لذلك أفضل الحلول لك هو أن تقوم بتصميم Tabcontrol من الصفر

ملحوظه اخيرة

الكود الذي كتبته اعلاه ينقصه بعض التعديلات البسيطه لكي يكون افضل قليلا وقد قمت بتعديله قليلا أتمني انه يكون مناسب لما تطلب علي الاقل في الوقت الحالي

حاليا عليك ان تكتفي بان تجعل TabPages في وضعها الطبيعي في اقصي اليسار



Public Class Form1

Private m_DarkColorDefault As Color = Color.FromArgb(255, Color.Black)
Private m_LightColorDefualt As Color = Color.FromArgb(255, 224, 224, 224)
Private m_DarkColorGold As Color = Color.FromArgb(255, Color.Orange)
Private m_LightColorGold As Color = Color.FromArgb(255, 255, 255, 192)

Private m_DarkColor As Color = Color.FromArgb(50, Color.Black)
Private m_LightColor As Color = Color.FromArgb(255, 224, 224, 224)


Private m_blend As New Blend
Private m_Factors As Single() = {0.0F, 0.2F, 0.5F, 0.7F, 1.0F, 0.7F, 0.5F, 0.2F, 0.0F}
Private m_Positions As Single() = {0.0F, 0.1F, 0.3F, 0.4F, 0.5F, 0.6F, 0.7F, 0.8F, 1.0F}


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed
TabControl1.SizeMode = TabSizeMode.Fixed

Dim tab_size As Size = TabControl1.ItemSize
tab_size.Width = 100
tab_size.Height += 6
TabControl1.ItemSize = tab_size

End Sub

Private Sub TabControl1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem

m_blend.Factors = m_Factors
m_blend.Positions = m_Positions

Dim string_format As New StringFormat
Dim txt_brush As Brush = Brushes.White
Dim m_font As New Font(Me.Font, FontStyle.Bold)

string_format.Alignment = StringAlignment.Center
string_format.LineAlignment = StringAlignment.Center
'e.Graphics.FillRectangle(Brushes.YellowGreen, TabControl1.ClientRectangle)
If e.State = DrawItemState.Selected Then

Using b As New LinearGradientBrush(e.Bounds, m_LightColorDefualt, m_DarkColorDefault, 90, True)
b.Blend = m_blend

e.Graphics.FillRectangle(b, e.Bounds)

End Using


e.Graphics.DrawString(TabControl1.TabPages(e.Index).Text, m_font, txt_brush, RectangleF.op_Implicit(e.Bounds), string_format)
e.DrawFocusRectangle()

Else

Using b As New LinearGradientBrush(e.Bounds, m_LightColorGold, m_DarkColorGold, 90, True)
b.Blend = m_blend
e.Graphics.FillRectangle(b, e.Bounds)
End Using


ControlPaint.DrawStringDisabled(e.Graphics, TabControl1.TabPages(e.Index).Text, m_font, BackColor, RectangleF.op_Implicit(e.Bounds), string_format)

End If


End Sub

Private Sub TabPage1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles TabPage1.Paint, TabPage2.Paint, TabPage3.Paint

m_blend.Factors = m_Factors
m_blend.Positions = m_Positions

Using b As New LinearGradientBrush(e.ClipRectangle, m_LightColor, m_DarkColor, 90, True)
b.Blend = m_blend

e.Graphics.FillRectangle(b, e.ClipRectangle)

End Using

End Sub


End Class
Imports System.Drawing.Drawing2D

بالتوفيق

أخوك عمر

تم تعديل هذه المشاركة بواسطة a_pess في 3 يناير 2009 في 07:27

#4

مرحباً أخي الكريم .

أو يمكنك الإعتماد على التالي :

 

[color= #000000; font-weight: bold;]Public [color= #000000; font-weight: bold;]Class Form1

 

    [color= #000000; font-weight: bold;]Private Sub TabControl1_DrawItem[color= #009900;](ByVal Sender [color= #b1b100;]As Object[color= #339933;], [color= #990000;]_

    ByVal E [color= #b1b100;]As [color= #990000;]System[color= #339933;].Windows[color= #339933;].Forms[color= #339933;].DrawItemEventArgs[color= #009900;]) Handles TabControl1[color= #339933;].DrawItem

        Dim CTabControl [color= #b1b100;]As TabControl [color= #339933;]= DirectCast[color= #009900;](Sender[color= #339933;], TabControl[color= #009900;])

        Dim Bmp [color= #b1b100;]As [color= #000000; font-weight: bold;]New Bitmap[color= #009900;](E[color= #339933;].Bounds[color= #339933;].Width[color= #339933;], E[color= #339933;].Bounds[color= #339933;].Height[color= #009900;])

        Dim Str [color= #b1b100;]As [color= #000000; font-weight: bold;]New StringFormat

        Dim Rect [color= #b1b100;]As [color= #000000; font-weight: bold;]New Rectangle[color= #009900;]([color= #cc66cc;]0[color= #339933;], [color= #cc66cc;]0[color= #339933;], Bmp[color= #339933;].Width[color= #339933;], Bmp[color= #339933;].Height[color= #009900;])

        Str[color= #339933;].Alignment [color= #339933;]= StringAlignment[color= #339933;].Center

        Str[color= #339933;].LineAlignment [color= #339933;]= StringAlignment[color= #339933;].Center

        Using G [color= #b1b100;]As Graphics [color= #339933;]= Graphics[color= #339933;].FromImage[color= #009900;](Bmp[color= #009900;])

            Dim F [color= #b1b100;]As Font [color= #339933;]= [color= #000000; font-weight: bold;]New Font[color= #009900;](E[color= #339933;].Font[color= #339933;], FontStyle[color= #339933;].Bold[color= #009900;])

            Dim B [color= #b1b100;]As [color= #000000; font-weight: bold;]New SolidBrush[color= #009900;](Color[color= #339933;].LightBlue[color= #009900;])

            G[color= #339933;].FillRectangle[color= #009900;](B[color= #339933;], Rect[color= #009900;])

            [color= #b1b100;]If E[color= #339933;].State [color= #339933;]= [color= #cc66cc;]1 Then B[color= #339933;].Color [color= #339933;]= Color[color= #339933;].Blue [color= #b1b100;]Else B[color= #339933;].Color [color= #339933;]= Color[color= #339933;].Black

            G[color= #339933;].DrawString[color= #009900;](CTabControl[color= #339933;].TabPages[color= #009900;](E[color= #339933;].Index[color= #009900;])[color= #339933;].Text[color= #339933;], F[color= #339933;], B[color= #339933;], Rect[color= #339933;], Str[color= #009900;])

            B[color= #339933;].Dispose[color= #009900;]([color= #009900;])

            F[color= #339933;].Dispose[color= #009900;]([color= #009900;])

            [color= #b1b100;]If Not CTabControl[color= #339933;].RightToLeft [color= #339933;]= [color= #cc66cc;]0 And CTabControl[color= #339933;].RightToLeftLayout [color= #339933;]= [color= #cc66cc;]1 Then

                Bmp[color= #339933;].RotateFlip[color= #009900;](RotateFlipType[color= #339933;].Rotate180FlipY[color= #009900;])

            [color= #990000;]End [color= #b1b100;]If

            E[color= #339933;].Graphics[color= #339933;].DrawImage[color= #009900;](Bmp[color= #339933;], E[color= #339933;].Bounds[color= #339933;].Location[color= #009900;])

        [color= #990000;]End Using

    [color= #990000;]End Sub

 

[color= #990000;]End [color= #000000; font-weight: bold;]Class

تم تعديل هذه المشاركة بواسطة Bashar Rabat في 3 يناير 2009 في 19:52

The important thing is not so much

that every child should be taught,

as that every child should be given the wish to learn.

#5

بسم الله الرحمن الرحيم

اخوه الأعزاء

السلام عليكم ورحنة الله وبركاته

الإخوة الأعزاء الشكر الجزيل لكل من اهتم وشارك وبارك الله بالجميع ، وسوف ادرس وافحص المشاركات

وشكرا

م.محمد

مواضيع مشابهة