|
I just starting to work on C# last month. Just bear with me if I show my lack of experiences. I am trying to make program that populating the list in propertygrid. I found good article for me like this:http://www.codeproject.com/cs/miscctrl/customizingcollectiondata.asp#xx653437xx . But, I really have problem with standard editor. I cant rid the ... button(I think it called modal) from propertygrid. I tried to use : public override UITypeEditorEditStyle GetStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.None;
}
but somehow it blocked me to show the list. For example, if I am using without codes above, then it will show whole list, but it showed the ... button(modal whatever it is) on the list that I dont want to see. If I am using with codes above, then it wont show the list at all but modal button wont appear at all. what is your suggestions about my situation?
about this articles that I linked, is there another way to make list in propertygrid instead using with CollectionBase, ICustomTypeDescriptor bec I dont like those?
My property grid should look like this:
CategoryAttribute:
+ ITEM1
+ ITEM2
+ ITEM3
+ ITEM4
+ ITEM5
Thanks in advance!!
|
|
|
|
|
Hi,
Software:
.NET 1.1 (both non-SP and SP1)
Visual Studio .NET 2003
MS SQL Server 2000 SP3
Windows XP SP 2
Hardware:
Intel Celeron 1700, Pentium 4 2.4GHz, AMD Athlon 1100
RAM 256-512 DDR
I've run into a strange problem. There is an application which allows to:
1) connect to a certain device using a modem
2) manage different aspects (mostly, working with MS SQL Server)
Serial communication is done on a separate thread, one per each connection.
The maximum number of simultaneous connections is 20.
Note: what is written below applies only when running the application not
under the debugger.
The app starts and works correctly: accepts incoming calls, performs
different scenarios, dials out when necessary. When the comms thread needs to
modify the UI, it is correctly done using Control.BeginInvoke. However,
sometimes (on different computers) the following exception is thrown:
System.OutOfMemory exception: error creating window handle --->
System.NullReferenceException: Object reference not set to an instance of
object.
at System.Windows.Forms.ThreadContext.OnThreadException
at System.Windows.Forms.Control.WndProcException
at System.Windows.Forms.ControlNativeWindow.OnThreadException
at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(int32, string,
string, int32, int32, int32, int32, int32, HandleRef, HandleRef, HandleRef,
object)
at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(int32, string,
string, int32, int32, int32, int32, int32, HandleRef, HandleRef, HandleRef,
object)
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams)
-- End of inner exception stack trace --
at System.Windows.Forms.ThreadContext.OnThreadException
at System.Windows.Forms.Control.WndProcException
at System.Windows.Forms.ControlNativeWindow.OnThreadException
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef, int32)
at System.Windows.Forms.Control.SetVisibleCore
at System.Windows.Forms.Form.SetVisibleCore
at System.Windows.Forms.Control.set_Visible
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog
at <my form-my="" code="" to="" showdialog="">
What could be the problem?
Let me stress that this does not happen under debuggers. When debugging, the
exception is not thrown. It was noted that this happens more often when
having an active connection.
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
I see from your stacktrace that you're using ShowDialog . When using modal dialogs, you need to make sure you dispose your forms or you will lose memory quickly. This isn't always a problem running under a debugger because the GC hasmore time to clean-up resources.
When displaying modal dialogs using ShowDialog , it's best to use the using block statement as below:
using (MyForm form = new MyForm())
{
form.ShowDialog();
} This compiles to something similar to this:
MyForm form = null;
try
{
form = new MyForm();
form.ShowDialog();
}
finally
{
if (form != null) ((IDisposable)form).Dispose();
} This way - even if an exception is thrown - the form's resources (i.e., the message pump on the new thread and other native resources used by the controls, since the controls merely encapsulate native Common Controls and other windows, are freed-up.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
|
I did implement the scheme you suggested, however I'm still having the same problems. Could you suggest anything else? Should I call GC.Collect() manually? Or any other ideas?
Also, I put [STAThread] attribute as suggested to me at MSDN managed newsgroups, which also didn't help.
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
I also met this problem days ago and finally found I set the value for a variable in wrong section(Notice the innerException). I set it in Form_Load(), and everything goes well when I move it to constructor. May this helps.
|
|
|
|
|
I was wondering if there is a built in function in C# that performs filling. I 'll give it the closed contour as an input and I need the filled contour as an output..Does anyone know a built in function that does that,or a ready made program that one did before that I could use. Please reply ASAP
EA
|
|
|
|
|
There are a number of articles with programming examples on this site (and others) relating to converting a bitmap to a region for irregularly shaped forms and controls. You can of course fill a region for any purpose
http://www.codeproject.com/csharp/bmprgnform.asp
Sorry I'm using FireFox, no clickety..
Gary
|
|
|
|
|
Hello!
My app open and shows HTML files.
I have a typical pdf-distiller printer driver on my system.
Is it possible to create a printfunction that print/save the shown HTML file automaticly?
- The user should only need to press the print button. I do not want the print dialog to be shown.
Any suggestions?
/sverre
|
|
|
|
|
I asked the same question a few months ago, and the answer was no
If you do find a method, please post me a reply!
Gary
|
|
|
|
|
|
Sorry maybe I wasn't clear..
When I asked the question, this is what I needed (still do).
I have written an application that uses / inherits from System.Drawing.Printing.PrintDocument.
Printing works perfectly for print preview and print to printer. I have Adobe PDF (full verion) installed, I want to bypass the question of filename and print directly to a supplied PDF file, .Net does not implement the Printer Setting PrintToFile so it is not possible to set the name of the file without the dialog appearing.
Please correct me if I'm wrong, I'd love to get this working.
Gary
While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'
- Dilbert
|
|
|
|
|
That's a different question, though it may be the same subject matter as what the other poster is having. I guess it's all about what details you give when asking. I was assuming both of you mean the Printer dialog that comes up like in applications when you click File -> Print...
PrinterSettings.PrintToFile is implemented, however. The problem is, IIRC, that the Adobe Distiller print driver has it's own prompt. From what I remember when using it (a version or two back) is that even if you had the printer driver's file set, it didn't affect Adobe's pseudo-printer driver. It would prompt you anyway. Try it just through windows.
What you could do, though, is print to a file in a directory watched by the capture application (can't remember the name, sorry; it's part of the full Acrobat install). If you use a PostScript driver (any PS driver will do) and print to a file in that directory with the .ps extension, this application will automatically convert it to PDF and put it in another directory.
This solution has worked for me in the past when I had to write clients on non-Windows platforms (like AS/400 and OS/2 Warp).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi Heath,
Heath Stewart wrote:
PrinterSettings.PrintToFile is implemented,
there is an article on the Microsoft site PrintDocument Class" Does Not Implement the PrintToFile Feature[^] which explains my problem better than I did
I have done something similar to your suggestion for another project, however in this case there is still the problem that I am prompted for the name of the file to print to, I want it to all be hidden from the user (my wife). I want to print to PDF and attach the PDF to an e-mail, all automatically.
Gary
While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'
- Dilbert
|
|
|
|
|
That's over a year old. I actually looked at the IL in the assembly and it is implemented and apparently passed to the print driver.
Once again, though, last time I used Acrobat Distiller I noticed that it prompts for a filename itself and does not use the print driver's "Print to file" setting.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Sure you can. You use the PrintDocument along with the Print method, which does not use the PrintDialog . You can specify the setting programmatically or read them from user settings (with defaults), which would be more appreciated by users that might need to tweak settings.
The .NET Framework SDK documentation also includes samples for using the XmlDocument class.
What's even easier is if you're embedding the WebBrowser control, you can use ExecWB to print without prompting like so:
object missing = Missing.Value;
axWebBrowser2.ExecWB(
OLECMDID.OLECMDID_PRINT,
OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
ref missing,
ref missing); This uses the browser's print rendering so that you don't have to - definitely something you should take advantage of if you're embedding the WebBrowser control.
You can also do something similar using the IOleCommandTarget interface with MSHTML if you're using that to render instead of dealing with the browser overhead.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello!
I receive errors when I try to compile your suggestion...
OLECMDID and OLECMDEXECOPT could not be found...
In which namespace are they located?
/sverre
|
|
|
|
|
These are structs declared for COM, so you first need to create an interop assembly. If you're using the WebBrowser control, you've already got that assembly. You need to reference either Interop.SHDocVw.dll or simply SHDocVw.dll (depending on how you imported the typelib; it could be any name, really). Then reference the only namespace that assembly defines. Again, this depends on how you imported it. If you just used VS.NET, then the namespace should be SHDocVw .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks!
It's working!!!
/sverre
|
|
|
|
|
Hello again!
The code you supplied printes on the default printer.
Is there any way to choose which printer to use?
/sverre
|
|
|
|
|
Have you even read the documentation for any of the printing classes, like the PrinterSettings[^] class?
You set the PrinterSettings.PrinterName to an installed printer, which you can enumerate using the static PrinterSettings.InstalledPrinters property. Depending on how you design your application, you can simply use the PrintDialog[^] class.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I really have...
I know how to print a plain txt file using the PrinterSettings-class. But I would like to print a HTML file.
I use this code to load and print it:
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
missing = System.Reflection.Missing.Value;
// create an instance of Internet Explorer
IWebBrowserApp wb = (IWebBrowserApp) ie;
// Navigate to the provided url
wb.Navigate("http://www.codeproject.com", ref missing, ref missing, ref missing, ref missing);
// print to default printer
ie.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref missing, ref missing);
// kill the instance of IE
ie.Quit();
This works, but I'm not able to choose which printer to use. The code above print directly to the default printer while I would like to decide which one to use. The PrintDialog is not an option as the user no userinteraction shall appear.
Is there a way to specify which printer to use when using "ie.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref missing, ref missing)"?
/sander99
|
|
|
|
|
If you read the documentation for ExecWB , as well as the MSHTML command ID documentation for IDM_PRINT (same as OLECMDID_PRINT ), you'd see there is no way to print to a specified printer. You can specify a custom print template, overrides to not bother the user or wait until completion, or specify a custom header, footer, and IStream (COM interface) for an Outlook Express header document.
Your only choice in this matter is to set whatever printer you want as the default, print, then set the default printer back (if you want to reset it).
If your application will only run on Windows 2000 or newer, you can P/Invoke SetDefaultPrinter :
[DllImport("winspool.dll", CharSet=CharSet.Auto)]
static extern bool SetDefaultPrinter(string printer); You could actually set CharSet to CharSet.Unicode since this is only supported in Windows 2000 and higher (in which case NT-based Windows platforms are all Unicode), but technically the API is defined using LPCTSTR , which is platform-dependent.
If you have to support any Windows platforms (i.e., not NT-based, so 95, 98, and Me, which is the last non-Unicode Windows platform - even Windows CE is Unicode), then the easiest way is to use WMI to set the default printer:
using System;
using System.Management;
using System.Reflection;
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyKeyName("dev")]
class Printers
{
static void Main(string[] args)
{
EnumeratePrinters(args.Length > 0 ? args[0] : null);
}
static void EnumeratePrinters(string defaultName)
{
ManagementObject defaultPrinter = null;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"select * from Win32_Printer");
foreach (ManagementObject printer in searcher.Get())
{
string name = printer["Name"].ToString();
Console.WriteLine("Printer: " + name);
if (defaultName != null &&
string.Compare(name, defaultName, true) == 0)
defaultPrinter = printer;
}
if (defaultPrinter != null)
{
Console.WriteLine("Setting default printer to \"{0}\"",
defaultPrinter["Name"]);
defaultPrinter.InvokeMethod("SetDefaultPrinter", null);
}
}
} This is just an example I threw together before for someone that both enumerates the printers in a platform-agnostic way, as well as sets the default printer if you specify a valid printer name on the command line.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello, i have a problem.
I have three table's:
Varekat: Vid, beskrivelse.
HovedGrp: Hid, Vid, beskrivelse.
UnderGrp: Uid, Hid, Beskrivelse.
I have a datagrid where I will show the values from these three tables (lookups), and save them in another tabel ('Vare'). I use ComboTextCol.ColumnComboBox, where i set the displaymember to be beskrivelse and the value member to be Vid (the id value from each table). This works fine as it is today. My problem is when I try to make a funcionality where the user choose a value from one of the comboboxes (from table UnderGrp), I want the values from Hovedgrp and VareKat to be selected automatically. The relation between the tables are that one post i Varekat can have several posts in HovedGrp and one post in HovedGrp can have several posts in UnderGrp.
I have made a relation between the tables, and tried to do the same with ordinary comboboxes, and it works fine, but when i use ComboTextCol.ColumnComboBox (in a datagrid) i can't use displaymember = "datarelation.beskrivelse" and valuemember = "datarelation.Hid" because I get errormessages when trying.
|
|
|
|
|
Knowing that ComboTextCol.ColumnComboBox isn't a class in the .NET BCL, it must be a third-party component you're using. I would recommend you seek help on any forums or mailing lists available from the publisher. It's extremely unlikely that any of us have ever used it (there's thousands of third-party controls out there) and it's the publisher's job to support it anyway (if they don't support their products, I recommend you choose another solution!).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|