Hi guys,
I'm working on a program where I need to change Text and ToolTips of different RadRibbonBar Elements.
The reason for this is that I need to be able to change the language on the fly.
This came as a request for an already existing program.
As the language will be changed for the whole program and all windows, I wanted to use a public function,
that will be called when I press a button and when a window is loaded / get the focus.
The Language information itself is stored in a database table.
Changing Text and ToolTips on Textbox, RadTextBox or other controls is no problem. I just can't find a way to iterate though a RadRibbonbar. Same counts for Tooltips on a RadGridView.
I added further table columns that hold names and types of RibbonBarElements as kind of a path to get to an element.
"radRibbonBar.ribbonTab.radRibbonBarGroup", "radRibbonBar<Form.Name>.ribbonTabMain.radRibbonBarGroupSave"
Still din't find a way to diretcly address a RadButtonElement for example.
There is another thread has some info but I'm still not able to figure out how to solve my problem
http://www.telerik.com/community/forums/winforms/ribbonbar/findcontrol-to-find-a-radbuttonelement.aspx
many thanks,
-Michael
I'm working on a program where I need to change Text and ToolTips of different RadRibbonBar Elements.
The reason for this is that I need to be able to change the language on the fly.
This came as a request for an already existing program.
As the language will be changed for the whole program and all windows, I wanted to use a public function,
that will be called when I press a button and when a window is loaded / get the focus.
The Language information itself is stored in a database table.
private
void
radButtonElementEnglish_Click(
object
sender, EventArgs e)
{
ChangeLanguage(
this
,
"English"
)
}
Changing Text and ToolTips on Textbox, RadTextBox or other controls is no problem. I just can't find a way to iterate though a RadRibbonbar. Same counts for Tooltips on a RadGridView.
I added further table columns that hold names and types of RibbonBarElements as kind of a path to get to an element.
"radRibbonBar.ribbonTab.radRibbonBarGroup", "radRibbonBar<Form.Name>.ribbonTabMain.radRibbonBarGroupSave"
Still din't find a way to diretcly address a RadButtonElement for example.
public
void
ChangeLanguage(Form frm, String Language =
"English"
)
{
RadTextBox RadTextBoxTip =
null
;
RadDropDownListCustom radDropDownListCustomTip =
null
;
RadLabel radLabelTip =
null
;
RadButtonElement radButtonElementTip =
null
;
RadGridView radGridViewTip =
null
;
SqlCommand commandGetData =
null
;
try
{
commandGetData = SQLQuery();
commandGetData.CommandText =
"SELECT Element_Name, Element_Typ, Element_Text_EN, ToolTip_Text_EN, Element_Text_DE, ToolTip_Text_DE, From Language WHERE Windowr_Name = @Window_Name"
;
commandGetData.Parameters.AddWithValue(
"@Window_Name"
, frm.Name.ToString());
commandGetData.Connection.Open();
SqlDataReader DataReader = commandGetData.ExecuteReader();
if
(DataReader.HasRows)
{
while
(DataReader.Read())
{
switch
(DataReader[
"Element_Typ"
].ToString())
{
case
(
"radTextBox"
):
RadTextBoxTip = (RadTextBox)frm.Controls.Find(DataReader[
"Element_Name"
].ToString(),
true
)[0];
if
(Language ==
"English"
)
{
RadTextBoxTip.Text = DataReader[
"Element_Text_EN"
].ToString();
RadTextBoxTip.TextBoxElement.TextBoxItem.ToolTipText = DataReader[
"ToolTip_Text_EN"
].ToString();
}
if
(Language ==
"German"
)
{
RadTextBoxTip.Text = DataReader[
"Element_Text_DE"
].ToString();
RadTextBoxTip.TextBoxElement.TextBoxItem.ToolTipText = DataReader[
"ToolTip_Text_DE"
].ToString();
}
break
;
case
(
"radLabel"
):
radLabelTip = (RadLabel)frm.Controls.Find(DataReader[
"Element_Name"
].ToString(),
true
)[0];
// same as radtextbox
//radLabelTip.Text
//radLabelTip.LabelElement.ToolTipText
break
;
case
(
"radRibbonbonbar"
):
//..
RadRibbonBar RadRibbonbarTip = (RadRibbonBar)frm.Controls.Find(DataReader[
"Element_Name"
].ToString(),
true
)[0];
//RadRibbonbarTip.Text = ..
//No Tooltip here
break
;
case
(
"ribbonTab"
):
//..
break
;
case
(
"radButtonElement"
):
var c = GetAll(frm,
typeof
(RadRibbonBar));
MessageBox.Show(
"Total Controls: "
+ c.Count());
break
;
//more case:
default
:
break
;
}
}
DataReader.NextResult();
}
commandGetData.Connection.Close();
}
catch
(System.Data.SqlClient.SqlException ex)
{
// showEvents(ex);
}
finally
{
if
(commandGetData !=
null
) { commandGetData.Dispose(); }
}
}
}
public
IEnumerable<Control> GetAll(Control control, Type type)
{
var controls = control.Controls.Cast<Control>();
return
controls.SelectMany(ctrl => GetAll(ctrl, type))
.Concat(controls)
.Where(c => c.GetType() == type);
}
There is another thread has some info but I'm still not able to figure out how to solve my problem
http://www.telerik.com/community/forums/winforms/ribbonbar/findcontrol-to-find-a-radbuttonelement.aspx
many thanks,
-Michael