|
Good day to all u programmers out there. Pls could you offer help on the following:
1. I enjoying programming and I also have a great love for database administration...where do I fit in?
2. I seldom use a tool for long before moving around to something new - low persistence...where do I fit in?
I know some of u are professions. Pls help me discover myself (direction and clear advice without any biase)...where do I fit in?
...the mind is not a vessel to be filled but a fire to ignited
|
|
|
|
|
You will get more responses by posting in the correct board.
I would recommend posting in one of the following:
Lounge
Work Issues
SoapBox
This board is for C# related questions, hence coding with C#.
R.Bischoff
.NET, Kommst du mit?
|
|
|
|
|
Ive some problems with tabpages
i have one form with one tabcontrol with one tabpage
The first tabpage contain a button.
When you click the button a new tabpage will be created and added to the tabcontrol.
This works.
But the second created tabpage contain a button to for closing that page. I used the next code:
((Tabcontrol)this.parent).Tabpages.remove (this);
It works but after i used these code i connot close the form (the close button doesnt work anymore) However a "Application.exit" command in the menus works.
Can anyone help me?
Ive another problem:
When i click the button in the first tabpage, how con i focus the second?
I used the
tabpage.focus ();
command but it doesnt work
Jonathan Slenders
|
|
|
|
|
When remove a TabPage or Control from a collection like this, make sure you do it in the main UI thread, no another thread. This can lead to problems processing the message loop that internally dispatches messages to the appropriate windows. There are other causes of this behavior and we've discussed it before. You could try searching the comments to find more causes.
Instead of TabPage.Focus , use TabControl.SelectedIndex or TabControl.SelectedTab :
TabPage page = new TabPage("Second");
tabControl1.TabPages.Add(page);
tabControl1.SelectedTab = page;
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
// The TabControl.SelectedIndex Property works good. Thanks for that.
// But i doesnt know how i can do it in another thread.
// Now i have created an instance of a class inheritted from the Tabpage.
// That class contain a property which refer to a function with the delegate:
public delegate void delRemoveTabPage (TabPage tabPage1);
// When i create that instance i set the RemoveTabPage property
TabPage1.RemoveTabPage += new delRemoveTabPage (RemoveTabpage);
// My RemoveTabPage function is these
void RemoveTabpage (TabPage tabPage1)
{
tabCtrlMain1.TabPages.Remove (tabPage1);
}
// It works (This tabpage disapears but the close butten doesnt work anymore like i said before.)
// Well, i have an other possibility but i don't know if this is good:
// the TabPage.Hide ( ) method works perfect. And if i add code in the tabpage thad set his childs
null i think there will be not mush memory used for thad hidden tabpage. Is this a good method?
|
|
|
|
|
Next time you post, please do not prefix each sentance with "//". It's very hard to read and completely unnecessary.
See the Control.InvokeRequired and Control.Invoke methods. These make sure that the action is performed in the main thread by invoking it from another method. For instance:
private delegate void RemoveHandler(TabPage);
private void removeButton_Click(object sender, EventArgs e)
{
Button b = sender as Button; if (b == null) return;
TabPage tab = b.Parent as TabPage; if (tab == null) return;
if (this.tabControl1.InvokeRequired)
{
RemoveHandler handler =
new RemoveHandler(this.tabControl1.TabPages.Remove);
this.tabControl1.Invoke(d, new object[] {tab});
}
else this.tabControl1.TabPages.Remove(tab);
} And no, simply hiding the tab is not a very good idea unless you plan on showing it again. When you're done with objects, dispose of them.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have a custom format, however, I want the abbreviated Month to be displayed all in uppercase. DateTime doesn't like this and I am a bit suck in how to accomplish this. I don't want to override the paint method.
Anyone got any ideas? Is there a helpfile class or something that the datetimepicker uses?
|
|
|
|
|
If you can't set your custom format with DateTimePicker.CustomFormat and DateTimePickerFormat.Custom properties you can implement IFormattable interface. Look into MSDN for more information.
Mazy
No sig. available now.
|
|
|
|
|
Basically I want to print some stuff from my program, it works just great on every single test machine, but on customer's computer when the printing should start I got an Arithmetic underflow or overflow exception at System.Drawing.Font.Init. The same error shows up when selecting some fonts (but I can still use those fonts from Word, ...) and closing the font dialog. To be even more strange if I print from an other program before starting my own printing it will work like a charm.
Does anybody meet something like this? Any hint would be great, I'm
|
|
|
|
|
dataTable1.RowChaging += new DataRowChangeEventHandler(dataTable1_rowChaing)
private void dataTable1_RowChanging(object sender, DataRowChangeEventArgs e)
{
if ( e.Action == DataRowAction.Add )
{
if (...)
throw new ApplicationException("不合法的检查项目!");
}
}
------------
the problem is :
this dataTable is associated to a datagrid, when add a new row through the datagrid, the rowchanging event can be trigered. If the row is invalid, the exception will be throwed, and the new row cannot be added to the dataTable1.
But when should I handle this Exception? I can't catch this exception.
|
|
|
|
|
You could create a handler for AppDomain.UnhandledException , but it might be simpler to just display an error or warning message box to the user with MessageBox.Show . With Windows XP and higher, they are now using balloons when invalid characters are typed, such as a backslash in a filename or another invalid character somewhere. You could always do something like that, too.
Basically, just don't throw the exception and instead provide feedback to the user.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
But if I don't throw the exception in RowChaging event, i can't prevent the new row to be added to the data table.
Or some way to do that?
|
|
|
|
|
Sorry about that. I've been doing so much control development lately I'm too used to such events being CancelEventHandler events (or similar)!
Yes, you'll have to throw the exception so add a handler to AppDomain.UnhandledException like I mentioned before. I recommend you also create a custom exception class that derives from ApplicationException (typically used for custom exceptions to give them a common, application-based base class) that you throw from the DataTable.RowChanging event handler. This way, you can easily just catch this exception in the handler for the AppDomain.UnhandledException event and handle appropriately, which is better than throwing such a oft-used exception and trying to determine where it came from and why it was thrown.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I did that. And I throw a ErrorDataRowException which inherits from Application in the data table's RowChanging event.
But when the ErrorDataRowException is thrown, the application didnot enter the method UnHandledExceptionHandler. Instead, the application still popup an window in which told me there is an unhandled exception.
why? pls help me.
[STAThread]
static void Main()
{
AppDomain currentAppDomain = AppDomain.CurrentDomain;
currentAppDomain.UnhandledException += new UnhandledExceptionEventHandler(UnHandledExceptionHandler);
FormRegisterConsole fmMain = new FormRegisterConsole();
Application.Run(fmMain);
}
private static void UnHandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
if (e.GetType() == typeof(Health.ApplicationLibrary.RIS.Register.ErrorDataRowException))
{
MessageBox.Show(e.Message, "data updating", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("出现未处理错误: " + e.Message, "未处理错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
|
|
|
|
|
Try Application.ThreadException then. I use the same thing in our program I designed at work but couldn't remember which event I was using. It's been a long time since I wrote that section of the container application.
Also, just a helpful tip: try the is keyword instead of obj.GetType() == typeof(SomeClass) . It results in fewer IL instructions (better performance) and, IMO, is a little easier to read:
public static void Main(string[] args)
{
Application.ThreadException +=
new ThreadExceptionEventHandler(UnhandledException);
Application.Run(new FormRegisterConsole());
}
private static void UnhandledException(object sender,
ThreadExceptionEventArgs e)
{
if (e.Exception is ErrorDataRowException)
{
}
else
{
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
how to prevent changing columns' width in datagrid?
|
|
|
|
|
You could derive from DataGridColumnStyle (or one of the derivative classes to avoid extra work) and override the Width property so that the set accessor does nothing. You'll have to have an internal property or a param in the constructor so you can set the initial width, though, which you can do by setting base.Width . This works in a quick test but still allows the user to drag the splitters (just doesn't actually change the width).
Upon inspection, the members you'd need to override are both private and are not virtual, nor do they use anything relevent that is overridable.
About the only thing I can think of is to override WndProc and handle mouse messages over the column header (which you can get the bounds of through various properties), not passing those to the base.WndProc .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
|
Hey, So I have some questions about technique when it comes to .net desktop development. My goal first off, is to be able to create an object on the desktop of my application and be able to pick it up and move it with the mouse. I'm convinced I could do this pretty easily using a Panel/Canvas object with a transparent background, however, I want for my objects to be non-rectangular. More precisely, polynomials of any fashion.
In Java, I used to just create an object that extended the Polygon class, and then assigned a MouseListener to it, check to see if the mouse being clicked was inside the polygon and wallah! C# and Java being so similar I would have expected this to be as well, however it does not seem so.
To elaborate, let me give an example. If anyone is experienced with diagram applications, like Visio, when you grab a line connecting two objects, you can draw it and manipulate it in almost any way you want. This can't possibly be a rectangular object. How is this done?
I'm curious about the technique used because it's something that seems a little less straight forward. However, I may be wrong. Please advise!
|
|
|
|
|
madjeux wrote:
C# and Java being so similar I would have expected this to be as well, however it does not seem so.
Just because the language syntax are similar does not mean they come with the same libraries. I'm not sure if it's possible to create a polygon and check if a point is inside it using GDI+, but it's a commonly solved problem, not so hard to do, plenty of info on the web.
madjeux wrote:
If anyone is experienced with diagram applications, like Visio, when you grab a line connecting two objects, you can draw it and manipulate it in almost any way you want. This can't possibly be a rectangular object. How is this done?
Figuring out if a point is on a specific line is very basic trig, even easier than the polygon problem. The best way to do this sort of stuff is to build a rectangle from the outermost points of the shape, quickly check if your point is inside it, and only then do the more complex test. I suggest that different objects all derive from a base class which defines abstract methods for drawing, for checking for hits, and so on. C# being too gay for multiple inheritance, you may want to derive from something else to get some other desired behaviour and define an interface for this stuff.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Ok, I gotcha. What I'm still fuzzy on is how to actually implement this in a wise way. For example, here's my code (which doesn't completely work yet).
using System;
using System.Windows.Forms;
namespace Test
{
public class Pipe : Control
{
public Pipe(){
}
protected override void OnMouseDown(MouseEventArgs e)
{
MessageBox.Show("a mouse was clicked and my object knows it");
base.OnMouseDown(e);
}
}
}
How do I add this to a form so that when a mouse is pressed, it distributes the event to my control? I was using "this.Controls.Add(new Pipe())" in initializeComponent, but it doesn't seem to work. Can someone please explain if what I am doing is retarded? Keep in mind, I am going to be adding to this class, but I just want to understand how I can have my components know when they are being clicked on. Thanks!
|
|
|
|
|
I Create The Componet myself,
i want to create my favourite Pict in the ToolBox
i search the information about it, but is show me example
below this.
// C#
// Specifies the bitmap associated with the Button type.
[ToolboxBitmap(typeof(Button)]
class MyControl : UserControl
// Specifies a bitmap file.
[ToolboxBitmap(@"C:\myImage.bmp")]
class MyControl : UserControl
[ToolboxBitmap(typeof(Button), @"C:\myimage.bmp")]
class MyControl : UserControl
how can i change the the absolute address' Picture
it means the picture include in my compont prject
in my class it like
[ToolboxBitmap(typeof(Button), @"myimage.bmp")]
class MyControl : UserControl
but how can i do
meetweb
|
|
|
|
|
When you use just a Type (the first constructor in your snippet), an image is used that has the same namespace and name as your class, but with a .bmp extension. I.e., if your class is Example.Class , then the image to be used is Example.Class.bmp . This image must be an embedded resource.
The second constructor is the name of an embedded resource, so you must include any namespace and the name of the file, like Example.Class.bmp .
The third constructor uses the namespace of the Type you pass in the first parameter and adds the name that you pass with the third constructor. If the class is Example.Class and you pass "Toolbox.bmp" as the name, then the image used is Example.Toolbox.bmp .
In all three cases, the image must be an emdedded resource, not a file on the computer. So, add a bitmap to your project, right-click and select Properties, then change the build type to "Embedded Resource".
You can find more details about this in the documentation for the ToolboxBitmapAttribute class in the .NET Framework SDK.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|