تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] مشكلة مع ال PictureBox شفاف ...
#1
السلام عليكم اخواني 

لدي مشكل مع الPictureBox  لدي صور شفافة اود ان تكون ملتصقة ببعضها  يعني الصور ليست مربعة بل هي على شكل متوازي اضلاع  حين افعل خاصية  شفاف  و الصق الصور لبعضها فامكان الشفاف يخفي الصورة الثانية  .

ما الحل و شكرا.


الملفات المرفقة صورة/صور
       
الرد }}}
تم الشكر بواسطة:
#2
هل من جواب ؟؟
الرد }}}
تم الشكر بواسطة:
#3
السلام اخي
الخلفية مقطعة و بصيغة PNG لكن حين اريد تقريب ال PictureBoxs لبعضها , القطعة الشفافة تخفي الPictureBox الثاني و كانها ليست شفافة
الرد }}}
تم الشكر بواسطة:
#4
من الواضح انك تحاول ان تقوم بصناعة باتون باستخدام الصور و لكي تحل مشكلتك فهناك اكثر من اسلوب عن طريق الكود
الحل الأول هو أن تقوم بالتخلص من لون الخلفية الموجود في الصورة ثم ترسم الصورة
الحل الثاني هو ان تقوم ببناء كلاس جديد يتم توريثه من الكلاس Control او من Label و ترسم الشكل الذي تريده مع حركة الماوس و كما اري من الصور الخاصة بك فمن السهل جدا رسم متوازي أضلاع وتملأه باللون المطلوب و تكتب التكست و ترسم الصورة الصغيرة
الرد }}}
تم الشكر بواسطة: سعود , mezri59
#5
يا مزري،

إذا كنت تضع كل صورة في PictureBox لوحدها فلا فائدة في هذه الطريقة لأن خلفية اداة PictureBox لن تكون شفافة.

الطريقة الناجحة هي رسم الصور في PictureBox واحدة طالما هي صور PNG يعني الأجزاء التي خارج متوازي الأضلاع شفافة.
الرد }}}
تم الشكر بواسطة: سعود , mezri59 , mezri59
#6
شكرا اخواني حللت المشكلة
بارك الله فيكم
الرد }}}
تم الشكر بواسطة:
#7
(16-06-16, 11:14 AM)mezri59 كتب : شكرا اخواني حللت المشكلة
بارك الله فيكم

هل من الممكن ان تقول الحل حتى نستفيد من تجربتك ؟
الرد }}}
تم الشكر بواسطة:
#8
(16-06-16, 03:02 AM)silverlight كتب : من الواضح انك تحاول ان تقوم بصناعة باتون باستخدام الصور و لكي تحل مشكلتك فهناك اكثر من اسلوب عن طريق الكود
الحل الأول هو أن تقوم بالتخلص من لون الخلفية الموجود في الصورة ثم ترسم الصورة
الحل الثاني هو ان تقوم ببناء كلاس جديد يتم توريثه من الكلاس Control او من Label و ترسم الشكل الذي تريده مع حركة الماوس و كما اري من الصور الخاصة بك فمن السهل جدا رسم متوازي أضلاع وتملأه باللون المطلوب و تكتب التكست و ترسم الصورة الصغيرة

اخي الكريم ممكن تفيدنا بالطريقة وجزاك الله خيرا
الرد }}}
تم الشكر بواسطة:
#9
الكود التالي يوضح الشكل المبدئي للكلاس الذي من الممكن تطويره عن طريق اضافة صفات اخري وأيضا من الممكن ان يتم إعادة عملية الرسم في الكلاس بطرق اخري مختلفة

PHP كود :
Imports System.ComponentModel
Imports System
.Runtime.CompilerServices
Imports System
.Windows.Forms.Design

<Designer(GetType(BitmapButton.BitmapButtonDesigner))>
Public Class 
BitmapButton
    Inherits PictureBox
    Implements IButtonControl
INotifyPropertyChanged

#Region "Field"

 
   Private _dialogResult As DialogResult
    Private _buttonState 
As ButtonState ButtonState.None

    
'  من الأأفضل هنا اضافة الصور للمشروع و اعطاؤها قيمة أولية لتجنب الأخطاء في تصميم الكونترول
    Private _defaultImage As Image = CType(Nothing, Image)
    Private _mousedownImage As Image = CType(Nothing, Image)
    Private _mouseoverImage As Image = CType(Nothing, Image)

#End Region


#Region "Constructor"

    Public Sub New()
        DoubleBuffered = True
        BackColor = Color.Transparent
        SizeMode = PictureBoxSizeMode.AutoSize
    End Sub

#End Region

#Region "Property"

    Protected Overrides ReadOnly Property DefaultSize As Size
        Get
            Return New Size(100, 25)
        End Get
    End Property

    Public Property DialogResult As DialogResult Implements IButtonControl.DialogResult
        Get
            Return _dialogResult
        End Get
        Set(value As DialogResult)
            _dialogResult = value
        End Set
    End Property

    Private Property State() As ButtonState
        Get
            Return _buttonState
        End Get
        Set(value As ButtonState)
            _buttonState = value
            OnPropertyChanged()
        End Set
    End Property

    Public Property DefaultImage As Image
        Get
            Return _defaultImage
        End Get
        Set(value As Image)
            _defaultImage = value
            OnPropertyChanged()
        End Set
    End Property

    Public Property MousedownImage() As Image
        Get
            Return _mousedownImage
        End Get
        Set(value As Image)
            _mousedownImage = value
            OnPropertyChanged()
        End Set
    End Property

    Public Property MouseoverImage() As Image
        Get
            Return _mouseoverImage
        End Get
        Set(value As Image)
            _mouseoverImage = value
            OnPropertyChanged()
        End Set
    End Property

    <Browsable(True)>
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
    <Category("Appearance")>
    <Description("Gets or sets the control text.")>
    Public Overrides Property Text As String
        Get
            Return MyBase.Text
        End Get
        Set(value As String)
            MyBase.Text = value
        End Set
    End Property

    <Browsable(True)>
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
    <Category("Appearance")>
    <Description("Gets or sets the font of the control text.")>
    Public Overrides Property Font As Font
        Get
            Return MyBase.Font
        End Get
        Set(value As Font)
            MyBase.Font = value
        End Set
    End Property

    <Browsable(False)>
    <EditorBrowsable(EditorBrowsableState.Never)>
    <Category("Appearance")>
    <Description(" Gets or sets the image of the control.")>
    Public Shadows Property Image() As Image
        Get
            Return MyBase.Image
        End Get
        Set(value As Image)
            MyBase.Image = value
        End Set
    End Property

#End Region

#Region "Method"

    Public Sub NotifyDefault(value As Boolean) Implements IButtonControl.NotifyDefault
        State = If(value, State Or ButtonState.Default, State And Not ButtonState.[Default])
    End Sub

    Public Sub PerformClick() Implements IButtonControl.PerformClick
        If CanSelect Then
            OnClick(EventArgs.Empty)
        End If
    End Sub

    Protected Overridable Sub OnPropertyChanged(<CallerMemberName> Optional propertyName As [String] = "")
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
        If propertyName = "DefaultImag" Then
            Image = DefaultImage
        End If
    End Sub


    Protected Overrides Sub OnMouseLeave(e As EventArgs)
        MyBase.OnMouseLeave(e)
        State = State And Not ButtonState.Mouseover
        Image = DefaultImage
    End Sub

    Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
        MyBase.OnMouseDown(e)
        State = State Or ButtonState.Mousedown
        Image = MousedownImage
    End Sub

    Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
        MyBase.OnMouseUp(e)
        State = State And Not ButtonState.Mousedown
        Image = If(((State And ButtonState.Mouseover) <> 0), MouseoverImage, _defaultImage)
    End Sub

    Protected Overrides Sub OnMouseEnter(e As EventArgs)
        MyBase.OnMouseEnter(e)
        State = State Or ButtonState.Mouseover
        Image = MouseoverImage
    End Sub

    Protected Overrides Sub OnTextChanged(e As EventArgs)
        MyBase.OnTextChanged(e)
        Refresh()
    End Sub

    Protected Overrides Sub OnClick(e As EventArgs)
        Dim currentOwner = Me.FindForm()
        If currentOwner IsNot Nothing Then
            currentOwner.DialogResult = _dialogResult
        End If
        MyBase.OnClick(e)
    End Sub

    Protected Overrides Sub OnPaint(pe As PaintEventArgs)
        MyBase.OnPaint(pe)

        If (Not String.IsNullOrEmpty(Text)) AndAlso (pe IsNot Nothing) AndAlso (MyBase.Font IsNot Nothing) Then
            Dim sb As New SolidBrush(MyBase.ForeColor)
            Dim textSize As SizeF = pe.Graphics.MeasureString(MyBase.Text, MyBase.Font)
            Dim pt As PointF = CType(Nothing, PointF)
            If MyBase.Image IsNot Nothing Then
                pt = New PointF(MyBase.Image.Width / 2 - textSize.Width / 2, MyBase.Image.Height / 2 - textSize.Height / 2)
            Else
                pt = New PointF(MyBase.Width / 2 - textSize.Width / 2, MyBase.Height / 2 - textSize.Height / 2)
            End If

            pe.Graphics.DrawString(MyBase.Text, MyBase.Font, sb, pt)

        End If


    End Sub

#End Region

#Region " Event"

    <Description("Occurs when a property value changes.")> <Category("Property Changed")>
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

#End Region

#Region "ButtonStates"

    Private Enum ButtonState
        None
        [Default]
        Mouseover
        Mousedown
    End Enum

#End Region

#Region "BitmapButtonDesigner"

    ' 
هذا الكلاس الهدف منه تغيير شكل البكتشربوكس الأصلي في مرحلة التصميم وذلك بعد تحويله الي باتون
    Friend 
Class BitmapButtonDesigner
        Inherits ControlDesigner

        Protected Overrides Sub PostFilterAttributes
(attributes As IDictionary)
 
           MyBase.PostFilterAttributes(attributes)
 
           Dim attr As Attribute = New DockingAttribute(DockingBehavior.Never)
 
           attributes(GetType(DockingAttribute)) = attr
        End Sub

        Public Overrides ReadOnly Property SelectionRules
() As SelectionRules
            Get
                Return SelectionRules
.Moveable
            End Get
        End Property

    End 
Class

#End Region

End Class 
الرد }}}
تم الشكر بواسطة: ابو روضة



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم