|
|
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]
|
|
|
|
|
Hello again. It isn't a third-part component, but i've found the solution on another forum. The ComboTextCol.ColumnComboBox code looks like this:
public class DataGridComboBoxColumn : DataGridTextBoxColumn
{
public NoKeyUpCombo ColumnComboBox;
private System.Windows.Forms.CurrencyManager _source;
private int _rowNum;
private bool _isEditing;
public static int _RowCount;
public DataGridComboBoxColumn() : base()
{
_source = null;
_isEditing = false;
_RowCount = -1;
ColumnComboBox = new NoKeyUpCombo();
ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
ColumnComboBox.Leave += new EventHandler(LeaveComboBox);
// ColumnComboBox.Enter += new EventHandler(ComboMadeCurrent);
ColumnComboBox.SelectionChangeCommitted += new EventHandler(ComboStartEditing);
}
private void ComboStartEditing(object sender, EventArgs e)
{
_isEditing = true;
base.ColumnStartedEditing((Control) sender);
}
private void HandleScroll(object sender, EventArgs e)
{
if(ColumnComboBox.Visible)
ColumnComboBox.Hide();
}
// private void ComboMadeCurrent(object sender, EventArgs e)
// {
// _isEditing = true;
// }
//
private void LeaveComboBox(object sender, EventArgs e)
{
if(_isEditing)
{
SetColumnValueAtRow(_source, _rowNum, ColumnComboBox.Text);
_isEditing = false;
Invalidate();
}
ColumnComboBox.Hide();
this.DataGridTableStyle.DataGrid.Scroll -= new EventHandler(HandleScroll);
}
protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
base.Edit(source,rowNum, bounds, readOnly, instantText , cellIsVisible);
_rowNum = rowNum;
_source = source;
ColumnComboBox.Parent = this.TextBox.Parent;
ColumnComboBox.Location = this.TextBox.Location;
ColumnComboBox.Size = new Size(this.TextBox.Size.Width, ColumnComboBox.Size.Height);
ColumnComboBox.SelectedIndex = ColumnComboBox.FindStringExact(this.TextBox.Text);
ColumnComboBox.Text = this.TextBox.Text;
this.TextBox.Visible = false;
ColumnComboBox.Visible = true;
this.DataGridTableStyle.DataGrid.Scroll += new EventHandler(HandleScroll);
ColumnComboBox.BringToFront();
ColumnComboBox.Focus();
}
protected override bool Commit(System.Windows.Forms.CurrencyManager dataSource, int rowNum)
{
if(_isEditing)
{
_isEditing = false;
SetColumnValueAtRow(dataSource, rowNum, ColumnComboBox.Text);
}
return true;
}
protected override void ConcedeFocus()
{
Console.WriteLine("ConcedeFocus");
base.ConcedeFocus();
}
protected override object GetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum)
{
object s = base.GetColumnValueAtRow(source, rowNum);
DataView dv = (DataView)this.ColumnComboBox.DataSource;
int rowCount = dv.Count;
int i = 0;
//if things are slow, you could order your dataview
//& use binary search instead of this linear one
while (i < rowCount)
{
if( s.Equals( dv[i][this.ColumnComboBox.ValueMember]))
break;
++i;
}
if(i < rowCount)
return dv[i][this.ColumnComboBox.DisplayMember];
return DBNull.Value;
}
protected override void SetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum, object value)
{
object s = value;
DataView dv = (DataView)this.ColumnComboBox.DataSource;
int rowCount = dv.Count;
int i = 0;
//if things are slow, you could order your dataview
//& use binary search instead of this linear one
while (i < rowCount)
{
if( s.Equals( dv[i][this.ColumnComboBox.DisplayMember]))
break;
++i;
}
if(i < rowCount)
s = dv[i][this.ColumnComboBox.ValueMember];
else
s = DBNull.Value;
base.SetColumnValueAtRow(source, rowNum, s);
}
}
public class NoKeyUpCombo : ComboBox
{
private const int WM_KEYUP = 0x101;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if(m.Msg == WM_KEYUP)
{
m.Result = System.IntPtr.Zero;
//ignore keyup to avoid problem with tabbing & dropdownlist;
return;
}
base.WndProc(ref m);
}
}
And I access it like this:
ComboTextCol = new DataGridComboBoxColumn();
Do you know a better way to get a combobox in a datagrid??
|
|
|
|
|
It may not be third-party, per se, but it is not a class defined in the .NET BCL. If you would've explained that it is a control you developed - even based on an article elsewhere - that would've been a different story. But when you just mention the class name without any sort of reference, it sounds like a third-party control.
The DataView in .NET 2.0 supports many more column types, including columns for ComboBox es. What you're doing right now for the DataGrid , however, is the best way of doing it. It's how the DataGridTextBoxColumn works, actually. A DataGridColumnStyle hosts a particular control when it's in edit mode. When it's not in edit mode, it merely paints the value.
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]
|
|
|
|
|
Ok. Good to hear. If we go back to my problem, I try to make combobox columns in my datagrid with code like this:
case 4:
ComboTextColvk = new DataGridComboBoxColumn();
ComboTextColvk.MappingName = "VareKategori"; //must be from the grid table...
ComboTextColvk.HeaderText = "VareKategori";
ComboTextColvk.Width = 120;
ComboTextColvk.ColumnComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
ComboTextColvk.ColumnComboBox.DataSource = relationDG1.Tables["UnderGruppe"].DefaultView;
ComboTextColvk.ColumnComboBox.DisplayMember = "UHR.VHR.Beskrivelse";
ComboTextColvk.ColumnComboBox.ValueMember = "UHR.VHR.VareKategoriId";//use for string value in combo
tableStyle.PreferredRowHeight = ComboTextColvk.ColumnComboBox.Height + 2;
ComboTextColvk.ColumnComboBox.Enabled = false;
tableStyle.GridColumnStyles.Add(ComboTextColvk);
break;
case 5:
ComboTextColhg = new DataGridComboBoxColumn();
ComboTextColhg.MappingName = "HovedGruppe"; //must be from the grid table...
ComboTextColhg.HeaderText = "HovedGruppe";
ComboTextColhg.Width = 120;
ComboTextColhg.ColumnComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
ComboTextColhg.ColumnComboBox.DataSource = relationDG1.Tables["UnderGruppe"].DefaultView;
ComboTextColhg.ColumnComboBox.DisplayMember = "UHR.Beskrivelse";
ComboTextColhg.ColumnComboBox.ValueMember = "UHR.HovedGruppeId";
ComboTextColhg.ColumnComboBox.Enabled = false;
tableStyle.PreferredRowHeight = ComboTextColhg.ColumnComboBox.Height + 2;
tableStyle.GridColumnStyles.Add(ComboTextColhg);
break;
case 6:
ComboTextColug = new DataGridComboBoxColumn();
ComboTextColug.MappingName = "UnderGruppe"; //must be from the grid table...
ComboTextColug.HeaderText = "UnderGruppe";
ComboTextColug.Width = 120;
ComboTextColug.ColumnComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
ComboTextColug.ColumnComboBox.DataSource = relationDG1.Tables["UnderGruppe"].DefaultView;
ComboTextColug.ColumnComboBox.DisplayMember = "Beskrivelse";
ComboTextColug.ColumnComboBox.ValueMember = "UnderGruppeId";
tableStyle.PreferredRowHeight = ComboTextColug.ColumnComboBox.Height + 2;
tableStyle.GridColumnStyles.Add(ComboTextColug);
break;
The relationDG1 dataset contains three tables UnderGruppe, HovedGruppe and VareKategori, I have made a Relation between the tabels.
One between UnderGruppe and HovedGruppe called UHR (have HovedGruppeId in both tables UnderGruppe and HovedGruppe), and another between HovedGruppe and VareKategori called VHR (have VareKategoriID in both tables HovedGruppe and Varekategori).
I'm doing this because I want that the user only shall select a UnderGruppe, then the values from HovedGruppe and VareKategori will be auto selected. All the values shall be saved in a fourth table called Vare.
I have tried the relation with three ComboBoxes in a windows form, and it works fine, but I get errors when I try to the same in a DataGrid, I get messages like this: UHR.Beskrivelse is not a column in table undergruppe and neither a relation.
Is there anyway I can get this to work in a Datagrid??
|
|
|
|
|