نمایش نتایج 1 تا 7 از 7

نام تاپیک: استفاده از ResourceManager برای فراخوانی آیتمهای ریسورس پروژه اصلی

Threaded View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #1
    کاربر دائمی آواتار ROSTAM2
    تاریخ عضویت
    اسفند 1390
    محل زندگی
    فارس
    پست
    1,677

    Question استفاده از ResourceManager برای فراخوانی آیتمهای ریسورس پروژه اصلی

    سلام.

    من یک Component سفارشی دارم که با استفاده از کلاس ResourceManger رشته رو از ریسورس تعیین شده در خصوصیت Resource از Component برای یک StatusLabel با رفتن ماوس روی اشیاء فراهم می کنه:

    این هم سورسش توی پروژه اصلی:


    Imports System.ComponentModel
    Imports System.Resources
    Imports System.Reflection
    Imports System.Threading
    Imports System.Globalization
    <ProvideProperty("Status", GetType(Control))> _
    Public Class StatusProvider
    Implements IExtenderProvider


    Private WithEvents StatusLabelValue As ToolStripLabel
    Public Property StatusLabel() As ToolStripLabel
    Get
    Return StatusLabelValue
    End Get
    Set(ByVal value As ToolStripLabel)
    StatusLabelValue = value
    End Set
    End Property
    Private Shared resourceMan As Global.System.Resources.ResourceManager
    '''<summary>
    ''' Returns the cached ResourceManager instance used by this class.
    '''</summary>
    <Global.System.ComponentModel.EditorBrowsableAttri bute(Global.System.ComponentModel.EditorBrowsableS tate.Advanced)> _
    Friend Shared ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
    Get
    If Object.ReferenceEquals(resourceMan, Nothing) Then
    Dim ResourceName As String = String.Format("{0}.{1}", My.Application.Info.AssemblyName, ResourceValue)
    Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager(ResourceNa me, GetType(StatusProvider).Assembly)
    resourceMan = temp
    End If
    Return resourceMan
    End Get
    End Property
    Private Shared ResourceValue As String = "Resources"
    <Description("Resources"), DefaultValue("Resources")> _
    Public Property Resource() As String
    Get
    Return ResourceValue
    End Get
    Set(ByVal value As String)
    ResourceValue = value
    End Set
    End Property
    Protected StatusControls As New Dictionary(Of Control, String)
    Public Sub SetStatus(Ctl As Control, Value As String)
    If Me.StatusControls.ContainsKey(Ctl) = False Then
    Me.StatusControls.Add(Ctl, Value)
    AddHandler Ctl.MouseEnter, AddressOf _MouseEnter
    AddHandler Ctl.MouseLeave, AddressOf _MouseLeave
    Else
    If Value = String.Empty Then
    Me.StatusControls.Remove(Ctl)
    RemoveHandler Ctl.MouseEnter, AddressOf _MouseEnter
    RemoveHandler Ctl.MouseLeave, AddressOf _MouseLeave
    Exit Sub
    End If
    Me.StatusControls(Ctl) = Value
    End If
    End Sub
    <Description("String Name in Resource. (@<ResName>)")> _
    Public Function GetStatus(Ctl As Control) As String
    If Me.StatusControls.ContainsKey(Ctl) = True Then
    Return Me.StatusControls(Ctl)
    Else
    Return ""
    End If
    End Function


    Public Function CanExtend(extendee As Object) As Boolean Implements System.ComponentModel.IExtenderProvider.CanExtend
    Return TypeOf extendee Is Control
    End Function
    Private Sub _MouseEnter(sender As Object, e As System.EventArgs)
    If Me.StatusLabel Is Nothing Then Exit Sub
    Dim Expr As String = Me.StatusControls(sender)
    If Expr.StartsWith("@") Then
    Me.StatusLabel.Text = ResourceManager.GetString(Expr.Remove(0, 1))
    Else
    Me.StatusLabel.Text = Expr
    End If
    End Sub

    Private Sub _MouseHover(sender As Object, e As System.EventArgs)

    End Sub

    Private Sub _MouseLeave(sender As Object, e As System.EventArgs)
    If Me.StatusLabel Is Nothing Then Exit Sub
    Me.StatusLabel.Text = String.Empty
    End Sub

    Private Sub StatusProvider_Disposed(sender As Object, e As System.EventArgs) Handles Me.Disposed
    For Each ctl As Control In Me.StatusControls.Keys
    RemoveHandler ctl.MouseEnter, AddressOf _MouseEnter
    RemoveHandler ctl.MouseLeave, AddressOf _MouseLeave
    Next
    End Sub
    End Class


    سوال: من اگر بخوام این کامپوننت رو در یک پروژه Class Library ایجاد کنم برای استفاده در پروژه های دیگر چطور می تونم به ریسورس موجود در پروژه هدف دسترسی داشته باشم؟!

    آخرین ویرایش به وسیله ROSTAM2 : سه شنبه 29 آذر 1401 در 22:05 عصر

تاپیک های مشابه

  1. سوال: استفاده از Dll در ریسورس
    نوشته شده توسط loo30fer در بخش مباحث عمومی دلفی و پاسکال
    پاسخ: 11
    آخرین پست: یک شنبه 16 مرداد 1390, 01:44 صبح
  2. سوال: ساخت انواع ریسورس و استفاده از آن
    نوشته شده توسط ansoft در بخش مباحث عمومی دلفی و پاسکال
    پاسخ: 0
    آخرین پست: پنج شنبه 25 فروردین 1390, 16:03 عصر
  3. ریسورس کردن فایل reg و استفاده از آن
    نوشته شده توسط Slytherin در بخش برنامه نویسی در 6 VB
    پاسخ: 5
    آخرین پست: سه شنبه 09 آذر 1389, 21:38 عصر
  4. برنامه قابل ریسورس شدن هستند یا نه؟
    نوشته شده توسط once4ever در بخش Java EE : نگارش سازمانی جاوا
    پاسخ: 6
    آخرین پست: یک شنبه 28 بهمن 1386, 10:44 صبح
  5. دستکاری ریسورس ها !
    نوشته شده توسط Farhad.B.S در بخش برنامه نویسی در Delphi
    پاسخ: 4
    آخرین پست: چهارشنبه 02 مهر 1382, 11:28 صبح

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •