Unable to change color of RepositoryItemButtonEdit in Devexpress Gridview vb.net - vb.net

I have a column in a DevExpress Gridview that consists of Buttons. I would like to change the color of all the buttons in that column.
Buttons have been created this way:
Dim WithEvents buttonAdd As RepositoryItemButtonEdit
buttonAdd = New RepositoryItemButtonEdit
buttonAdd.TextEditStyle = TextEditStyles.HideTextEditor
buttonAdd.Buttons(0).Kind = ButtonPredefines.Glyph
Buttons are put in GridView1 this way:
Dim unbColumn As GridColumn = Gridview1.Columns.AddField("Button!")
unbColumn.VisibleIndex = Gridview1.Columns.Count
unbColumn.ColumnEdit = buttonAdd
Gridview1.OptionsView.ShowButtonMode = DevExpress.XtraGrid.Views.Base.ShowButtonModeEnum.ShowAlways
I have tried:
buttonAdd.Buttons(0).appearence()..... but nothing allows me to change the color of the button.

The same question is already discussed in the context of the RepositoryItemButtonEdit how to change the backcolor thread in DevExpress Support Center.
In short, you can't change the colors when using skinning because the skinning is based on images and colors defined in skins. You should either disable skins and then use the Appearance's properties or modify skins.

Related

Scroll vertical dynamically in tabPage control

In my relatively simple project I have a two page tabControl. tabPage2 consists of dynamically created pictureBoxes (thumbnails, pic_XXX). tabPage2 is of fixed size, with AutoScroll enabled.
On tabPage1, among other things, I can search for a given name (pic_XXX). When I switch to tabPage2 I'd like it to be scrolled, so the row in which pic_XXX is, is visible. Manually scrolling in tabPage2 is working.
I'm struggling to dynamically scroll tabPage2 to accomplish this. The following solution throws an exception:
Dim pos As Point = tabPage2.Controls.Item("pic_" & imgNum).Location
tabPage2.VerticalScroll.Value = pos.Y
tabPage2.refresh()
I run out of ideas!?
So how to scroll the specified child control into view on an auto-scroll enabled control?
You should use method .ScrollControlIntoView( [Control] )
tabPage2.ScrollControlIntoView(tabPage2.Controls.Item("pic_" & imgNum) )
Answer for your question:
Dim pos As Point = tabPage2.Controls.Item("pic_" & imgNum).Location
tabPage2.VerticalScroll.Maximum = tabPage2.Height
tabPage2.VerticalScroll.Value = pos.Y
tabPage2.PerformLayout()
You have to call .PerformLayout() to make the scrolling control update.

Background Image Is Other Image Vb.net [duplicate]

In my C# Form I have a Label that displays a download percentage in the download event:
this.lblprg.Text = overallpercent.ToString("#0") + "%";
The Label control's BackColor property is set to be transparent and I want it to be displayed over a PictureBox. But that doesn't appear to work correctly, I see a gray background, it doesn't look transparent on top of the picture box. How can I fix this?
The Label control supports transparency well. It is just that the designer won't let you place the label correctly. The PictureBox control is not a container control so the Form becomes the parent of the label. So you see the form's background.
It is easy to fix by adding a bit of code to the form constructor. You'll need to change the label's Parent property and recalculate it's Location since it is now relative to the picture box instead of the form. Like this:
public Form1() {
InitializeComponent();
var pos = label1.Parent.PointToScreen(label1.Location);
pos = pictureBox1.PointToClient(pos);
label1.Parent = pictureBox1;
label1.Location = pos;
label1.BackColor = Color.Transparent;
}
Looks like this at runtime:
Another approach is to solve the design-time problem. That just takes an attribute. Add a reference to System.Design and add a class to your project, paste this code:
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Design; // Add reference to System.Design
[Designer(typeof(ParentControlDesigner))]
class PictureContainer : PictureBox {}
You can just use
label1.Parent = pictureBox1;
label1.BackColor = Color.Transparent; // You can also set this in the designer, as stated by ElDoRado1239
You can draw text using TextRenderer which will draw it without background:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics,
overallpercent.ToString("#0") + "%",
this.Font,
new Point(10, 10),
Color.Red);
}
When overallpercent value changes, refresh pictureBox:
pictureBox1.Refresh();
You can also use Graphics.DrawString but TextRenderer.DrawText (using GDI) is faster than DrawString (GDI+)
Also look at another answer here and DrawText reference here
For easy for your design.
You can place your label inside a panel. and set background image of panel is what every image you want. set label background is transparent
After trying most of the provided solutions without success, the following worked for me:
label1.FlatStyle = FlatStyle.Standard
label1.Parent = pictureBox1
label1.BackColor = Color.Transparent
You most likely not putting the code in the load function. the objects aren't drawn yet if you put in the form initialize section hence nothing happens.
Once the objects are drawn then the load function runs and that will make the form transparents.
private void ScreenSaverForm_Load(object sender, EventArgs e)
{
label2.FlatStyle = FlatStyle.Standard;
label2.Parent = pictureBox1;
label2.BackColor = Color.Transparent;
}
One way which works for everything, but you need to handle the position, on resize, on move etc.. is using a transparent form:
Form form = new Form();
form.FormBorderStyle = FormBorderStyle.None;
form.BackColor = Color.Black;
form.TransparencyKey = Color.Black;
form.Owner = this;
form.Controls.Add(new Label() { Text = "Hello", Left = 0, Top = 0, Font = new Font(FontFamily.GenericSerif, 20), ForeColor = Color.White });
form.Show();
Using Visual Studio with Windows Form you may apply transparency to labels or other elements by adding using System.Drawing; into Form1.Designer.cs This way you will have Transparency available from the Properties panel ( in Appearance at BackColor ). Or just edit code in Designer.cs this.label1.BackColor = System.Drawing.Color.Transparent;

Not able to set the Backcolor of label as Transparent

Using properties of "label" not able to set the backcolor as transparent ... when i select the color transparent from the option which is showing some color as backcolor, if transparent works properly must show background instead of some colors. please help
If you add a control at design time when setting the background to transparent it 'displays' the background of the form not the control on which it was placed unless that control is a container such as a panel.
2 options:
1 place the label on a panel and the label then displays the panel background (which can be a picture if that is what you are trying to do)
2 place the label programatically i.e.
dim Label1 As New Label
Control.Controls.Add(Label1)
Label1.BackColor = Color.Transparent

How do I make a group box's text bold but not the text of controls contained in it?

I went and created a tab containing a good amount of controls, most of which are contained within what I'll just call the top-level group box. Now I decide I'd like the text of the top-level group box to be bold, but nothing else. When I set the top-level group box's font to bold, however, all of the controls contained within it become bolded as well, which is what I don't want. I can set each individual control's bold property to false, but it seems like there should be an easier way to do this. Any ideas?
I'm probably missing something obvious, like a group box property that is staring me in the face--and apologize if this turns out to be the case.
Thanks in advance for any help.
You could bypass the problem by placing a label over the caption for the GroupBox, but I wouldn't necessarily recommend this.
A better solution emerges once you understand what is happening and why it is happening. The issue is that a control's font (among other things) is an ambient property, meaning that child controls inherit their parent/container control's properties. So if you set the GroupBox to use a bold font, all of its child controls automatically inherit the bold property by default.
The key there is, of course, by default. Ambient properties only apply if you don't explicitly set the properties of the children to something else. If you don't want the child controls to be bold, select them all and turn off bold. The settings of the parent/container will no longer override the new custom settings.
To make things even easier, you can add a Panel control to your GroupBox, dock/anchor it to fill the entire client area of the GroupBox control, and set it to use a standard, non-bold font. Then, the rules of ambient controls stipulate that the child controls you add to the Panel will not be bold by default. This way, you only have to change the font property of one control as opposed to every child control that you add to the GroupBox.
The reason that this is better than trying to add a Label control over the GroupBox caption is because a GroupBox is designed to contain controls. You can take advantage of the docking and anchoring properties to make sure that everything gets arranged correctly, and you won't have to fight the designer when doing so to make sure that your custom Label correctly covers up the default label drawn by the GroupBox control. Additionally, you won't run into Z order issues or have other redrawing problems rear their ugly heads at runtime when, for example, the Label control gets accidentally hidden behind the GroupBox and no one can see it (and a host of other potential snafus).
I came across this old question when searching for the same, and realised it could be solved in code without adding a separate control just to overcome the ambience issue that Code Gray mentions in his answer.
Add an extensions in a module like so:
<Extension()>
Public Sub UnBold(Of T As Control)(cc As Control.ControlCollection)
For Each c As Control In cc
If Not TypeOf c Is T AndAlso c.GetType.GetProperty("Font") IsNot Nothing Then
Dim RegularFont As New Font(c.Font.FontFamily, c.Font.Size, FontStyle.Regular)
c.Font = RegularFont
ElseIf c.HasChildren Then
UnBold(Of T)(c.Controls)
End If
Next
End Sub
Then unbold all the controls in all the GroupBoxes on a form (including any child GroupBoxes) by using as follows in the form's OnLoad event:
Me.Controls.UnBold(Of GroupBox)()
Or for all controls in a single GroupBox (again, including any child GroupBoxes):
MySpecificGroupBox.UnBold(Of GroupBox)()
With the proviso that if you actually want control within the GroupBox to actually stay emboldened you will have to set that in code after calling the extension.
Consider bypassing the problem by placing a label over the GroupBox's text area and make the label's font bold.
I did it once and even used a CheckBox (for enabling/disabling the whole group). Worked like a charm.
Place all of your controls inside of a ContentControl and reset the font parameters
<GroupBox Header="Group" FontSize="16" FontWeight="Bold">
<ContentControl Margin="0" FontSize="12" FontWeight="Regular">
...
...
...
</ContentControl>
</GroupBox>
Programatically you can do it in order. Assume you want to make font style bold in groupbox but not in child controls. First set the font to a new Font in child controls, in this case you can pass groupbox font property. Then change groupbox font style to bold.
var grpBox = new GroupBox()
{
Text = "",
Width = 780,
Height = 70,
Parent = panel1,
Dock = DockStyle.None,
AutoSize = false,
Visible = true,
Location = new Point(20, grpY)
};
var label = new Label()
{
AutoSize = true,
Parent = grpBox,
Enabled = true,
Name = "label" + btnNum++,
Location = new Point(5, 50),
Text = "",
Font = new Font(grpBox.Font, FontStyle.Regular)
};
var txtBox = new TextBox()
{
Width = 550,
Height = 23,
Location = new Point(65, 20),
Name = "txtBox" + btnNum++,
Parent = grpBox,
Enabled = true,
Tag = label,
Font = new Font(grpBox.Font, FontStyle.Regular)
};
grpBox.Font = new Font(grpBox.Font, FontStyle.Bold);

vb.net tabpage using a form for tabpanels issues

I have a simple vb.net form a tabpanel strip, and then a seperate form which is loaded for the tabpage.
Here is the code for the button that dynamically creates new tabs:
Dim tempTab As New TabPage
initTab(tempTab)
xt.TabPages.Add(tempTab)
xt.SelectedIndex = xt.TabCount - 1
Here is the code for the "initTab":
Dim tmpTab As New MainTab
tmpTab.Dock = DockStyle.Fill
tmpTab.Panel1.Dock = DockStyle.Fill
tab.Controls.Add(tmpTab)
tab.Text = "Untitled"
tab.Name = " "
I can easily set the focus of any tab by entering following which sets the focus for example to the last tab:
xt.SelectedIndex = xt.TabCount - 1
Now the issue is, how can I set the focus to a textbox on the custom form (in my example labeled "MainTab")? I've tried virtually everything I can google and I can't seem to find any example of how to setfocus or even set/get anything from the MainTab form.
Anyone can help me?
Erm, turning a form into a child control takes some surgery. You have to set its TopLevel property to false, hide the border, make it visible. I don't see it in the code snippet, is MainTab actually a form?
Anyhoo, you cannot use the Focus() method on a control until it is visible. Odds are good that it isn't visible yet in your code snippet. Use the Select() method instead. Say:
tmpTab.TextBox1.Select()
Or just set the TabIndex property of the first control that should get the focus to 0 in the designer.
xt.Controls(xt.SelectedIndex).Controls("TEXTBOXNAME").Focus()
Just make sure that you set the Name property of the textbox you want to have focus (in this case the name would be TEXTBOXNAME) if you do it like this.