in my mobile 6.5 application i have one check box shown in start of my listview using this code
ListBatch.Columns.Add(" ", 30, HorizontalAlignment.Left);
ListViewItem lvi = new ListViewItem(new string[] {String.Empty,"2","3"});
lvi.Checked = false;
but how can i have two checkboxes????
You'd have to custom draw the ListView. You might also use a DataGrid and custom format it.
Related
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;
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.
Hi Imm trying to use the Class TextToolStripSeparator, as provided here.
How to add informative text to menu strip separator in vb.net or C#
I am having dificulty implementing the solution. I have placed the classes in and have created a separator but I can't seem to figure out how to place the text. I am using a dynamicaly created ContextMenuStrip in a datagridview from a right click.
Dim menu As ContextMenuStrip = New ContextMenuStrip
Dim NewSep1 As New TextToolStripSeparator
menu.Items.Add(NewSep1)
menu.Show(Me, pt.X, pt.Y)
when I tryto add text like menu.Items.Add(NewSep1("-test-")) I get an error:
Error 1 Class 'myprog.TextToolStripSeparator' cannot be indexed because it has no default property.
What am I doing wrong?
It looks like you need to set the seperator's .Text property.
Dim NewSep1 As New TextToolStripSeparator
NewSep1.Text = "-test-"
menu.Items.Add(NewSep1)
Im writting an Application for Win8 with C# and Xaml.
I have an Control with an Control-Template, i can add Components statically to the Control-Template.
But when i add Them in the Code Behind like this:
TextBlock Text = new TextBlock();
Text.Name = "Text" + rand.Next(999999);
Text.Text = info.Name;
The Textblock is not shown when i add the Control to an Page.
You need to add the newly created controls to the hosting control. e.g., if you have a stackpanel you can add the textbox to it with something like
TextBlock Text = new TextBlock();
Text.Name = "Text" + rand.Next(999999);
Text.Text = info.Name;
myStackPanel.Children.Add(Text);
note : untested, but I'm pretty sure the syntax is right
I'd like to bold the text for a tab page under certain conditions (not, necessarily, GotFocus). Is it true the only 'er easiest way to do this is by overriding the DrawItem event for the tab control?
http://www.vbforums.com/showthread.php?t=355093
It seems like there should be an easier way.
Like ...
tabControl.TabPages(index).Font = New Font(Me.Font, FontStyle.Bold)
That doesn't work, obviously.
When you set the Font property on a TabPage, you are setting the default font for all controls on that tab page. You are not setting it for the header, however.
When you execute the following code:
tabControl.TabPages(index).Font = New Font(Me.Font, FontStyle.Bold)
Any controls on that page will now be bold by default, which is not (I'm assuming) what you want.
The header's font (that is, the tab itself) is controlled by the TabControl's Font property. If you were to change your code to:
tabControl.Font = New Font(Me.Font, FontStyle.Bold)
You will see that in action. However, it changes the font for all the tabs on display, which is also not, I'm assuming, what you want.
So, using the default WinForms tab control, you are (I believe) limited to the technique in the link you've posted. Alternatively, you can begin looking at 3rd-party controls, such as those discussed in these questions on StackOverflow.
An easy way to give tab controls different labels depending on a field value is to change the caption itself:
For example:
Private Sub Form_Current()
If IsNull(Me.Subform.Form.Field_Name) Then
Me.Tab_Name.Caption = "Tab One"
Else
Me.Tab_Name.Caption = "Tab One +++"
End If
End Sub
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
Font BoldFont = new Font(tabControl1.Font, FontStyle.Bold);
e.Graphics.DrawString(tabControl1.TabPages[e.Index].Text, BoldFont, Brushes.Black, e.Bounds);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
}