|
I have no idea if this is usable in a DataGridView in place of the TextBox normally used in a TextBox Column, but it was fun to write. Once you get a feeling for how easy it is to make new Controls (UserControls), or sub-class existing Controls (make Components), you can develop hybrids for special purposes very easily. The "craft" in it is getting the alignments and re-sizing right.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace March17_StateTracking
{
public partial class TBEllipse : TextBox
{
private readonly Label tLabel;
public Label TheLabel { set; get; }
public TBEllipse()
{
InitializeComponent();
tLabel = new Label();
TheLabel = tLabel;
tLabel.Text = "…";
tLabel.FlatStyle = FlatStyle.Flat;
tLabel.BorderStyle = BorderStyle.None;
tLabel.BackColor = Color.Gainsboro;
tLabel.TextAlign = ContentAlignment.TopRight;
tLabel.Margin = new Padding(0, 0, 0, 0);
tLabel.AutoSize = true;
Controls.Add(tLabel);
tLabel.Left = Width - tLabel.Width;
tLabel.Show();
tLabel.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
tLabel.MouseClick += tLabel_MouseClick;
tLabel.MouseHover += tLabel_MouseHover;
}
public TBEllipse(IContainer container)
{
container.Add(this);
InitializeComponent();
}
private void tLabel_MouseClick(object sender, MouseEventArgs e)
{
tLabel.BackColor = Color.Gainsboro;
}
private void tLabel_MouseHover(object sender, EventArgs e)
{
tLabel.BackColor = Color.Lime;
}
}
} After creating an instance of this ... you can test it by drag-dropping it from the ToolBox to a Form after it is compiled ... you can subscribe to the Click Event of the Label. Here's an example of creating an instance in code and adding it to a Form's ControlCollection when a Button on the Form is clicked:
private void TestTBEllipse_Click(object sender, EventArgs e)
{
TBEllipse testTBEllipse = new TBEllipse();
testTBEllipse.Text = "some text";
this.Controls.Add(testTBEllipse);
testTBEllipse.Location = new Point(400,400);
testTBEllipse.TheLabel.Click += TheLabel_Click;
}
private void TheLabel_Click(object sender, EventArgs e)
{
MessageBox.Show("ellipsis label clicked");
}
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
|
|
|
|
|
Why not just add a column of buttons next to the text column. The simplest and easiest way to do this would be to add an unbound DataGridViewButtonColumn to the DataGridView in the DataBindingComplete event and then handle the CellContentClick event to respond to button clicks.
Sample event handlers for a DataGridView 'dgv' on a Form 'Form1'
int buttonColumnIndex;
public Form1() {
InitializeComponent();
dgv.CellContentClick += new DataGridViewCellEventHandler(dgv_CellContentClick);
dgv.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dgv_DataBindingComplete);
}
private void dgv_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) {
DataGridViewButtonColumn bc = new DataGridViewButtonColumn();
bc.Name = "ButtonColumn";
bc.HeaderText = "";
bc.UseColumnTextForButtonValue = true;
bc.Text = "Edit";
bc.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
buttonColumnIndex = dgv.Columns.Add(bc);
dgv.Columns[buttonColumnIndex].DisplayIndex = 0;
}
private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e) {
if (e.ColumnIndex == buttonColumnIndex) {
MessageBox.Show(String.Format("Edit button clicked on row {0}", e.RowIndex));
}
}
Alan...
|
|
|
|
|
Thanks Alan, I am at present using button column. Actually this textbox with button idea is the inspiration from some popular Accounting softwares. They use in variety of there data entry forms, like for e.g Invoice, when user enter line item, there is column ProductID, when user enters ProductID column he/she can directly enter Product ID or use the ellipse button to show a lookup form. This looks cool, so I thought may be there are some ways we can do it in C# winforms, and by the look of all posts here I am now sure there are more then one ways.
Thanks to all for helping me..I am trying to learn to create custom control, and if there is no success I will stick to button column approach.
|
|
|
|
|
The area of a normal polygon can be calculated using the shoelace formula however one of its limitations is that it must not be complex. I am trying to calculate this given an array of co-ordinates. For the example points:
2,2
1,1
0,2
1,3
1,0
I have been able to construct a script which returns any valid interception points, in the above case this was:
1,1
It then reprints the points in order (including the interception points) in an array with an additional column which is equal to one if the point was added due to it being a valid interception point. This turned out to be:
2,2,0
1,1,0
0,2,0
1,3,0
1,1,1
1,0,0
Now the interception co-ordinate is added in the correct spot to the array of co-ordinates. The task which I am having problems with is being able to calculate the area of a self intercepting polygon. I understand that a complex polygon may be broken up into several simple polygons but do not know how you could write code to do this, or if knowing the interception point the area can be calculated without splitting it up. Any help would be appreciated, Cheers.
I have tried using the logic that four lines will point away from the interception and if you know two of them are connected by another line then that area must be one of the enclosed areas but for more complex polygons (which have multiple intercepts) this does not always work.
|
|
|
|
|
|
Hello Guys,
I am Developing an Application in Visual Studio 2012 to get some heat transfer parameters as output with some temperature/area inputs. The equations that I want to code in for getting a "heat Transfer Coefficient" are non-linear in nature with cube roots and fourth roots. Such equations can be solved in a single line of code in Mathematica or Matlab but Visual Studio I dont know how can I solve them and return the value. Any help will be appreciated. A sample of such equations in one variable is listed below:
[2*[T+298]^3 + 1.2 * (T-298)^1/3]* [T-298]= [338-T]/0.2
I have to solve for T.
Thank you in Advance.
Nadish
|
|
|
|
|
I'd try an interative approximation: start with some value for T, calculate the formula, change T a little, calculate again, compare the results, and decide for another approximation of T, till you think your result is sufficiently "exact".
|
|
|
|
|
|
Is it the Fully Qualified Type Name?
|
|
|
|
|
I think the basic idea for the syntax of a "generic" parameter in .NET is that it can be any group-of-glyphs (set of characters) that meaningfully serve as a "place-holder" that will hold, at run-time, any valid .NET Type.
A convention that has developed, and which is used in many books about C# .NET ... though I am not sure it has ever been formalized in the C# language specification ... is to use single characters like "T," and "U," etc., for generic parameter names.
In terms of the syntax of the .NET Types you pass to some Method that receives generic parameters, I think whether or not you must use a fully qualified Type Name depends on the name-scope context in effect at the moment you wish to pass the Type.
So, if you have valid "using" statements in effect, then you can just pass the current valid variable name by itself; if the context does not already provide the ability to use the current name alone, then you must use the fully qualified Type name. Hopefully, you would get a compile-time error if you did not include all the required access syntax for any variable.
Am I understanding what you are asking here correctly ?
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
modified 17-Mar-14 2:13am.
|
|
|
|
|
BillWoodruff wrote: Am I understanding what you are asking here correctly ?
Nope, but that's because I didn't explain to well.
Let me elaborate.
If I have a Generic class Generic<T> and two normal classes ClassA and ClassB that can be used as Generic<ClassA> and Generic<ClassB> .
How does the Generic<T> class (or actually the compiler) tell the two classes apart? What does the compiler use to identify a class?
The reason that I was asking is that I was trying to use generics with dynamically created classes.
Which of course doesn't work, because the compiler doesn't know about those classes at compile time.
So today the question is merely of academic value to me. But atleast I've learned how to create a class at runtime.
|
|
|
|
|
The clue is in the IL. Consider this assembly:
namespace JorgenQuestion
{
class Program
{
static void Main(string[] args)
{
Chooser<ClassA> chooser = new Chooser<ClassA>();
Chooser<ClassB> chooser2 = new Chooser<ClassB>();
}
}
public class ClassA
{
}
public class ClassB
{
}
public class Chooser<T>
{
}
} Now, the IL that's produced out for the Program class is this:
.class private auto ansi beforefieldinit JorgenQuestion.Program
extends [mscorlib]System.Object
{
.method public hidebysig specialname rtspecialname instance void .ctor () cil managed
{
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
}
.method private hidebysig static void Main (
string[] args
) cil managed
{
.entrypoint
.locals init (
[0] class JorgenQuestion.Chooser`1<class JorgenQuestion.ClassA> chooser,
[1] class JorgenQuestion.Chooser`1<class JorgenQuestion.ClassB> chooser2
)
IL_0000: nop
IL_0001: newobj instance void class JorgenQuestion.Chooser`1<class JorgenQuestion.ClassA>::.ctor()
IL_0006: stloc.0
IL_0007: newobj instance void class JorgenQuestion.Chooser`1<class JorgenQuestion.ClassB>::.ctor()
IL_000c: stloc.1
IL_000d: ret
}
} As you can see, the newobj statements are instantiating the correct classes.
|
|
|
|
|
That's fascinating, Pete: thanks !
I am trying to imagine a real-world scenario in which using the type of generic Classes in this example would be useful, but drawing a blank. Any ideas ?
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
|
|
|
|
|
I can't come up with anything either.
|
|
|
|
|
Thanks for confirming.
I wish I could give you an extra upvote for doing it by example.
My knowledge map sadly says "Here be monsters" where it should say IL.
So that's added on my todo list.
|
|
|
|
|
You're welcome. I do find that dropping down to the IL can be a real eye opener at times.
|
|
|
|
|
Do you have any reading to recommend, or should I just get my hands dirty?
|
|
|
|
|
Just get your hands dirty. I learned IL by writing simple, predictable console applications that exercised different parts of the language and then I looked to see what was produced. Of course, I was lucky enough to be forced down this route because I wrote a code generator back in about 2004 and I had to really get my head around the way IL worked to fully understand what I was producing.
|
|
|
|
|
I have the following objects:
public class Parent
{
public BaseChild Child {get;set;}
}
public class BaseChild
{
}
public class ChildOne : BaseChild
{
public string Member {get;set;}
}
"Parent" is mapped to a "Parent2" type from a different module (which has the same member BaseChild).
Mapper.CreateMap(typeof(Parent), typeof(Module2::Parent2));
Mapper.CreateMap(typeof(BaseChild), typeof(Module2::BaseChild));
Mapper.CreateMap(typeof(ChildOne ), typeof(Module2::ChildOne ));
I'm creating a Parent object:
Parent parent = new Parent
{
Child = new ChildOne { Member = "Test" }
}
And try to convert:
object parent2 = Mapper.Map(parent, parent.GetType(), typeof(Module2::Parent2));
I get the following exception from auto mapper:
----------
{AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Mapping types:
ChildOne -> BaseChild
Test.ChildOne -> Test.BaseChild
----------
I need this mapping to work in order to be able to convert objects from a new "Parent2" type (in the 2nd module) to an old one.
How do I make it support inherited types of members in a converted class?
|
|
|
|
|
Hi,
I am able to use API DllImport("user32.dll") for FindWindow, GetCursorPosition then use sendkys to enter some number\text into an other GUI application ... through its Title & Class (ie: Windows Calculator!
However if I don't use API Mouse to move in other sections ... I can't not go directly them (with Autoit I can use with Title & Advanced Class = Advanced (Class): [CLASS:Button; INSTANCE:72] )
My question is there any way I can do that with Vsual C# and How?
Thanks to any help
|
|
|
|
|
Well, it AutoIt, there is code behind the scenes that is parsing and interpreting that "Advanced (Class): [CLASS:Button, INSTANCE:72])" stuff. There is NOTHING in the Windows API that has any idea what that string means or what to do with it.
You're asking about how to write the code that AutoIt has inside that does just that. For that, you would have to ask the people who wrote AutoIt. Good luck with that!
|
|
|
|
|
Might be the way I asking wasn't right, I do work well with Autoit ... but I have to work with Visual C# now! I am not expert in Visual C#, that was why I would like to know there is a similiar way to access direct an instance of a GUI or not? I thought Visual C# a well-known SW should have a better way than a free Autoit (it can't even build a DLL or a distribution application)
If there isn't a way, then I will have to use mouse method to move to the area I want to access ... but this ia the bad way, because if the people move the GUI to other position or change the screen resolution ... the mouse will move to wrong location
I hope that you aren't upset because of a people who just wants to know there is any thing available
modified 16-Mar-14 16:08pm.
|
|
|
|
|
Member 10636998 wrote: I would like to know there is a similiar way to access direct an instance of a GUI or not
No, there isn't. The only way you've got is the one you're already using, FindWindow, ...
|
|
|
|
|
Hi Dave,
In this case I don't have to search for it any more!
Thanks for the confirmation.
|
|
|
|
|
I want to create an application where I can load the excel file or the set the path in the code(hard coded) and the program will create the table in SQL Server. The data in the top column will be the name of the fields.
Assuming that Database is already created and the name of excel file will be the name for the table.
So I want to know how to approach this task and what things I need to consider.
Thanks
|
|
|
|