i have this class for example:
class labeledtext
{
private TextBox tb;
private Label l;
public labeledtext(Form frm)
{
tb = new TextBox();
l = new Label();
frm.Controls.Add(tb);
frm.Controls.Add(l);
}
public void SetCaption(string cpt)
{
l.Text = cpt;
}
public string text()
{
return tb.Text;
}
}
I want to make an object from this class, that can be used in any other project, as a visual object. I want to use it like a text box, drag it from toolbox to my form and put it and so on.
how can i do this?
I use visual studio 2010, if it is important.
I think you're looking for a user control.
In the solution explorer, right click, new usercontrol.
You can draw it in design time, and you can drag it wherever you want. (It will appear in the toolbar after you build the solution).
Here is a little guide: LINK
Related
i am currently working on my own TabControl, just to give me more options in customization.
To come along with this, i've made my own TabPage too.
Edit: Rewrote my question with pictures:
I want this Field:
After Clicking on "Collection" you gain a new Box to "Add" and "Remove" the Values
So here's what i've done:
If i now hit "Add" some pages appear, if i hit "remove" some pages disappear.
So far so good.
Clicking on "OK" does not show them up (but they are still there, after reopening the menu)
Now the random stuff happens:
If i press "Cancel" all the 'tabs' are generated.
If i open the menu again, all the "tabPages" are shown as there ClassType.
Here is the code of my TabControl Class
//The List for my TabPages
List<FancyTabPage> listPages = new List<FancyTabPage>();
//My Wrapper to get the Menu for the Designer shown in the Picture
public List<FancyTabPage> Pages
{
set { this.listPages = value; drawTabPages(); }
get { return this.listPages; }
}
//My function to generate the buttons
private void drawTabPages()
{
this.Controls.Clear();
resizeTabPages();
int zaehlerMax = listPages.Count;
for (int zaehler = 0; zaehler != zaehlerMax; zaehler++)
{
this.Controls.Add(listPages[zaehler].PageButton);
}
}
I need to call acadcolor component from visual studio.when i add the component it's fine.
After I need to use that component so just I drag and drop that control to windows form visual studio automatically closed without passed any message.
Can anybody know how to add and how to work with acadcolor component from visual studio?
Thanks advance.
Here's an ADN article on just what Alex Filipovici was mentioning:
Use 64-bit ActiveX Component from a .NET Assembly
There are other alternatives too. Here's an ADN article replicating the control with WPF: WPF Implementation To Mimic Color Layer Controls.
You can also open the color dialog if it's to select a color. That's what I've done most recently:
using acColor = Autodesk.AutoCAD.Colors;
using acWindows = Autodesk.AutoCAD.Windows;
//...
public acColor.Color GetAutoCADColor()
{
acWindows.ColorDialog colorDialog = new acWindows.ColorDialog();
DialogResult dialogResult = new DialogResult();
dialogResult = colorDialog.ShowDialog();
switch (dialogResult)
{
case DialogResult.OK:
return colorDialog.Color;
case DialogResult.Cancel:
return Color.Empty.ConvertToAutoCADColor();
default:
return Color.Empty.ConvertToAutoCADColor();
}
}
Extension methods:
internal static class ColorExtensions
{
internal static Color ConvertToWindowsColor(this acColor.Color acColor)
{
return Color.FromArgb(acColor.ColorValue.ToArgb());
}
internal static acColor.Color ConvertToAutoCADColor(this Color winColor)
{
return acColor.Color.FromRgb(winColor.R, winColor.G, winColor.B);
}
}
Just a thought or two.
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
create custom tooltip C#
Does anyone know of a way to make a box 'popup' when the user cursors over a certain item?
For example, I want to have a PictureBox on a C# forms application and when the user cursors over it, a box of text will pop up.
I'm aware of ToolTip however I was thinking of something more customisable; in my mind I'm thinking of the kind of popup boxes you see in World of WarCraft when you cursor over an item in your inventory (obviously it doesn't have to be THAT flashy, but at least one where the text colour, background colour, text etc. are all modifiable).
You can use a ToolStripControlHost to host a control (for instance a panel) and add the content you want. Then you add that control to a ToolStripDropDown using the Items collection, and use the Show(Control,Point) method to show the control.
Thought I'd add an example
public class Form1 {
public Form1() {
ToolStripDropDown customToolTip = new ToolStripDropDown();
customToolTip.Items.Add(new CustomPopupControl("Hello", "world"));
MouseMove += (o, e) => {
Point location = e.Location;
location.Offset(0, 16);
customToolTip.Show(this, location);
};
}
class CustomPopupControl : ToolStripControlHost {
public CustomPopupControl(string title, string message)
: base(new Panel()) {
Label titleLabel = new Label();
titleLabel.BackColor = SystemColors.Control;
titleLabel.Text = title;
titleLabel.Dock = DockStyle.Top;
Label messageLabel = new Label();
messageLabel.BackColor = SystemColors.ControlLightLight;
messageLabel.Text = message;
messageLabel.Dock = DockStyle.Fill;
Control.MinimumSize = new Size(90, 64);
Control.Controls.Add(messageLabel);
Control.Controls.Add(titleLabel);
}
}
}
I mean if it a button or an image button you can add something like MouseHover action and then show your message
private void button1_MouseHover(object sender, System.EventArgs e)
{
MessageBox.Show("yourmessage");
}
you need to customize the tooltip. refer to
http://www.codeproject.com/Articles/98967/A-ToolTip-with-Title-Multiline-Contents-and-Image
There are some other articles there, but this one works fine for me.
You may need to add code for your requirement.
I'm trying to create a DevEx drop down button. Unfortunately, I'm running into two problems I can't figure out:
1) I can't get the popup menu to skin correctly, i.e. it doesn't skin as "Office 2010 Blue". The code I'm using is shown below:
private void InitializeSendToPricingSheetButton()
{
var barManager = new BarManager();
if (barManager.Controller == null) barManager.Controller = new BarAndDockingController();
barManager.Controller.PaintStyleName = "Skin";
barManager.Controller.LookAndFeel.UseDefaultLookAndFeel = false;
barManager.Controller.LookAndFeel.SkinName = "Office 2010 Blue";
barManager.ItemClick += HandleSendToPricingSheetClick;
barManager.Items.AddRange(new[] { new BarButtonItem(barManager, "Foo"), new BarButtonItem(barManager, "Bar"), new BarButtonItem(barManager, "Baz") });
var popupMenu = new PopupMenu { Manager = barManager };
foreach (var barItem in barManager.Items) popupMenu.ItemLinks.Add((BarItem)barItem);
popupMenu.ItemLinks[1].BeginGroup = true;
dropDownButtonSendToPricingSheet.DropDownControl = popupMenu;
}
2) This button is on a form. If the form loses focus (e.g. I click on Firefox), the pop-up menu still remains on-top. It won't go away until clicked.
Any suggestions would be much appreciated. Thanks for helping me deal with DevEx insanity.
I have solution to your second question.
You should add drop down button event handler as below:
dropDownButton1.LostFocus += new EventHandler(HidePopUp);
Handler method should be as below:
private void HidePopUp(object sender,object e)
{
dropDownButton1.HideDropDown();
}
For your second question, you should assign value to the bar manager property as:
BarManager manager = new BarManager();
manager.Form = this; // refers to current form
Find below link for reference
https://www.devexpress.com/Support/Center/Question/Details/Q274641
It is probably simpler to use DefaultLookAndFeel
Add this comp to your form and set the theme you'd like to use.
There is no need to set the theme for individual components.
defaultLookAndFeel1.LookAndFeel.SetSkinStyle("Office 2010 Blue");
I have created a textBox control on run-time for my winform application. The control appears just find once the form loads up, and works great too. However, I have just run into a problem as I realize I do not know how to write the code to write to a dynamically created control.
Let's assume I have created a button (named "Button1") on design time. In Button1's click event, (Button1_Click), I would like to write the word "Hello" to a textBox control that won't be created until the application is executed. Some code below:
C# Code:
// Create the textBox control
TextBox new_textBox = null;
int x = 10;
int y = 10;
int xWidth = 300;
int yHeight = 200;
new_textBox = new TextBox();
new_textBox.Text = controlText;
new_textBox.Name = "textBox" + controlName;
new_textBox.Size = new System.Drawing.Size(xWidth - 10, yHeight - 10);
new_textBox.Location = new Point(x, y);
new_textBox.BringToFront();
new_textBox.Multiline = true;
new_textBox.BorderStyle = BorderStyle.None;
// Add the textBox control to the form
this.Controls.Add(new_textBox);
The Problem:
From Button1_Click event, I cannot get in contact with a control that has not even been created yet. Thus, Visual Studio will throw an obvious error that the control does not exist (because it doesn't).
So, is there some way to dynamically call a control, and more
specifically, a textBox control?
Thank you for any help on the matter,
Evan
Declare the new_textBox at class scope. Then the compiler can access it. For example:
class MyForm
{
TextBox new_textBox;
void InitializeTextBox()
{
new_textBox = new TextBox();
// initialization code here
// Add it to the form
this.Controls.Add(new_textBox);
}
void Button1_Click(...)
{
new_textBox.Text = "clicked";
}
You can make the new_textBox a class member (member of the form). You can again assign it a value and add to the forms controls later dynamically.
It would be a good practice to check if is null in the buttonClick event, though.