RightToLeft.Inherit

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I wrote a component using class library wizard. In my component i want to in
order to RightToLeft property do some works.
I can find out if user set this property to Yes or No, But if He/She set it
to Inherit I must examine its parent RightToLeft property(if i`m wrong please
tell me) but in this component that inherits from
System.ComponentModel.Component, How can i find parent???
In UserControls we can simply use Parent property but in this kind of
components, how we can find parent.

Thanks in advance.
 
Mohammad,
To the best of my knowledge, at run time, there is no 'Inherit' value, it
can only be Yes/No.
What I actually mean is that any control/component that has its RightToLeft
set to inherit at design time will inherit its parent direction somewhere in
its runtime lifecycle and before you can see it.

again, this is just based on my past experience and not facts.

Picho
 
Dear Picho
I wrote an if statement that checks if the my control RightToLeft property
is set to yes or no, but when ever i set main form(Parent of my control)
RightToLeft to Yes and my component to Inherit no one of if statements works.
 
I see.
I probably misunderstood you.

A Component has no Internal RightToLeft support. I thought you were talking
about a Control/UserControl.
If that is the case, you should implement a Parent property yourself that
implements direction control (any Control object), and then sign to its
RightToLeftChanged event.

Picho
 
this is a simple almost complete example:

// Code start:
using System;

namespace ParentPropertyExample
{
public class RTLComponent : System.ComponentModel.Component
{
private System.Windows.Forms.Control _parent;
private System.Windows.Forms.RightToLeft _rightToLeft;
private bool _inheritRightToLeft;

public RTLComponent()
{
}
public RTLComponent(System.Windows.Forms.Control parent)
{
this.Parent = parent;
}

public System.Windows.Forms.Control Parent
{
get
{
return _parent;
}
set
{
if (_parent==value)
return;

if (_parent!=null)
_parent.RightToLeftChanged-=new
EventHandler(this.ParentRightToLeftChanged);

_parent = value;
_parent.RightToLeftChanged+=new
EventHandler(this.ParentRightToLeftChanged);

if (this.DesignMode)
return;

if (!_inheritRightToLeft)
return;

if (this.Parent==null)
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
else
this.RightToLeft = this.Parent.RightToLeft;
}
}

public System.Windows.Forms.RightToLeft RightToLeft
{
get
{
return _rightToLeft;
}
set
{
if (this.DesignMode)
{
if (value==System.Windows.Forms.RightToLeft.Inherit)
_inheritRightToLeft = true;
else
_inheritRightToLeft = false;
}

_rightToLeft = value;
}
}

private void ParentRightToLeftChanged(object sender, EventArgs e)
{
if (this.DesignMode)
return;

if (!_inheritRightToLeft)
return;

if (this.Parent==null)
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
else
this.RightToLeft = this.Parent.RightToLeft;
}
}
}
// code end

talk to me again if it is not clear - have no time to explain right now -
sorry,

Picho
 
Thank you very much Picho

Picho said:
this is a simple almost complete example:

// Code start:
using System;

namespace ParentPropertyExample
{
public class RTLComponent : System.ComponentModel.Component
{
private System.Windows.Forms.Control _parent;
private System.Windows.Forms.RightToLeft _rightToLeft;
private bool _inheritRightToLeft;

public RTLComponent()
{
}
public RTLComponent(System.Windows.Forms.Control parent)
{
this.Parent = parent;
}

public System.Windows.Forms.Control Parent
{
get
{
return _parent;
}
set
{
if (_parent==value)
return;

if (_parent!=null)
_parent.RightToLeftChanged-=new
EventHandler(this.ParentRightToLeftChanged);

_parent = value;
_parent.RightToLeftChanged+=new
EventHandler(this.ParentRightToLeftChanged);

if (this.DesignMode)
return;

if (!_inheritRightToLeft)
return;

if (this.Parent==null)
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
else
this.RightToLeft = this.Parent.RightToLeft;
}
}

public System.Windows.Forms.RightToLeft RightToLeft
{
get
{
return _rightToLeft;
}
set
{
if (this.DesignMode)
{
if (value==System.Windows.Forms.RightToLeft.Inherit)
_inheritRightToLeft = true;
else
_inheritRightToLeft = false;
}

_rightToLeft = value;
}
}

private void ParentRightToLeftChanged(object sender, EventArgs e)
{
if (this.DesignMode)
return;

if (!_inheritRightToLeft)
return;

if (this.Parent==null)
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
else
this.RightToLeft = this.Parent.RightToLeft;
}
}
}
// code end

talk to me again if it is not clear - have no time to explain right now -
sorry,

Picho
 
Back
Top