|
I really don't think is for much help showing the code, but here it is:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(llistOfFileNames[listBox1.SelectedIndex].FullName);
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.DocumentText = sr.ReadToEnd();
sr.Dispose();
}
modified on Sunday, May 22, 2011 10:44 AM
|
|
|
|
|
why don't you just provide a valid web page, something like:
object item=ListBox1.SelectedItem;
if (item!=null) webBrowser1.DocumentText="<html><body><img src='"+item+"'></body></html>";
BTW: SelectedIndexChanged will also fire when something gets deselected, possible causing unexpected values for SelectedIndex, SelectedItem, etc.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Sunday, May 22, 2011 11:38 AM
|
|
|
|
|
And if, for some reason, you don't have or don't want to use a local file, there is always this[^].
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
merlinq12 wrote: I really don't think is for much help showing the code, but here it is:
Show the related code - in this case HTML maybe?
Are URLs correct?
Does the hosting process have permissions to access the local images?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
there are pages saved from internet... nothing fancy... they open alright in firefox browser(just to be sure their links are working alright).
|
|
|
|
|
The best thing to do is provide the *fully* qualified path (or url) for the file in question.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Hello,
I create 4000 files word like this :
foreach (string s in FUSIONSS_1)
{
String[] tbStr2 = s.Split(new Char[] { ';' });
string nb = tbStr2[0];
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
oWord.Visible = true;
oWord.Visible = false;
Object oTemplatePath = modelee;
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
{if (range.Text.Trim().Contains("P"))
{ int pos = range.Text.Trim().IndexOf("P");
string str = range.Text.Trim().Replace("P", "O");
range.Text = str;} }
Directory.CreateDirectory((Object)path + "./PUBLI/" + nb);
Object oSaveAsFile = (Object)path + "./PUBLI/" + nb + "/" + nb + ".doc";
oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
}
unfortunately the process winword.exe don't be kill on the task manager of my server.
How i can close the word file correctly?, thank you verry mutch.
|
|
|
|
|
|
Do you really need to create and dispose of the word application, and the other objects, 4000 times? Don't you think it would be better to do this outside of the loop?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Try changing the first oMissing to false.
abbd wrote: oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Word may be hanging on a hidden prompt to save changes or suchlike.
|
|
|
|
|
Unfortunately i have the same problem, please help me.
|
|
|
|
|
Well, I used to have a similar problem automating Excel in the same way. Best way to troubleshoot it is to NOT run it invisible for the time being. Then you can see what the problem might be.
|
|
|
|
|
Hello,
How in can run it invisible for the time being? please help me to resolve this great big problem.
|
|
|
|
|
oWord.Visible = true;
oWord.Visible = false;
Take out that second line.
You're running this on a server, right? NOT a good idea according to Microsoft (and my experience).
Also check your DCOM settings to be sure permissions are there for remote running. (I don't remember how to do it...Google will help.)
Actually, the best advice is to find another way to do it. If you can use Word 2007, while not necessarily easier, it's more likely to work beause you don't actually need Word on the server.
(I'll be gone this week, so can't help much. Maybe try Questions & Answers for more.)
|
|
|
|
|
Hello CP, I am back with another question. I am currently displaying data on a form like this:
There is a pie chart that is anchored to the top of the form. Beneath the chart I have a combobox which can alter the chart type. Beneath the chart type selection is the data I have questions about.
For now I am using simple Label controls and I display (each one on a separate label):
Total: 2
Model Model Total Most Common Failure
12345 100 Bad Part #1
54321 15 Bad Part #2
The labels' text is generated simply by retrieving data from the database and appending each model, model total and most common failure to the corresponding label's existing text. This method works.
However, I was approached by my immediate supervisor at work (who is the person I take requests from) about this. He asked if it is possible to make each Model item clickable (hence my link label idea) and display data based on the one specific model. I know I can dynamically generate link labels and set their location accordingly. However, is this an efficient solution or could I go about providing the desired result in another way?
I will continue to Google for possible solutions and if I find a better solution I will post here.
Thanks CP.
|
|
|
|
|
Hi,
I would say LinkLabels work exactly the same as regular Labels; you can add them through Visual Designer, or by executing some code (All Visual Designer ever does is generating such code, typically in a file with a name ending on Designer.cs ).
However, if your data is structured, you should not be using individual labels or linklabels. Consider using a DataGridView instead. It is a more complex control, however it knows about rows and columns (pretty much like a table in a database), you can make it hold any number of rows automatically, have it scroll when its content grows beyond its borders. And you can make it load its data automatically through "data binding".
Some more features that may interest you:
- choose how the data looks in each column, or even in individual cells;
- react to a cell being clicked;
- get the rows sorted based on the column header you click.
Mind you, if you have never used it, it may take some reading up to get acquainted.
I have one example on-line, in my article CP Vanity[^]. It is not the simplest example one could come up with, however it could give you an idea of what is possible.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks, Luc, but I do not think that is the necessary solution. There is not a large amount of data being displayed. The data will almost always fit without the need for scrolling. I simply need a way to have each model clickable and clicking it will display the data in a separate form (I am leaning toward a simple popup-like control). The data that will display is not for permanent viewing, as it is more for quick reference.
I hope I explained the problem more clearly. I find it difficult at times to explain exactly what is going on through simple text. :-P
|
|
|
|
|
Which controls you use is up to you, there is a number of them included in Windows and available as .NET WinForm Controls. You can also build your own, based on UserControl. And there are a large number of commercially available Controls too.
I am very much in favor of ListBox and DataGridView as soon as there is a list of things to be displayed. I would never put 10 or more Controls of the same type on a Form, it becomes hard to program, and performance goes down.
I forgot to mention: you can make a Label react to a click too, there is no need to have a LinkLabel, just look at the Click event.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yeah, I understand what you're saying. I did get it working with the labels. Thanks much, Luc.
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
i'm trying to get the unicode value of a character when the character is given , for example, i can get the character using
string s = '\u0061';
so the character is assigned to s , but now i want the vise versa , means i want to get the unicode of the s , the result should be '\u0061'.
any one gat an idea .
thanx in advance.
|
|
|
|
|
Not tested:
string unicode = string.Format("'\\u{0:X4}'", (int)s[0]);
|
|
|
|
|
thanx it works for me thax again.
|
|
|
|
|
He everyone,
within a application i've use a PrintPreviewControl. When calling ProntPage a error-message occour:
<b>Not ImplementedException System.Collections.ListDictionaryInternal</b>
The error comes up in Line:
<b>e.Graphics.DrawImage ( Image, 10,10 );</b>
But only if the program runs within Windows XP (Svp3). Doing under Windows 7 all works well. Ive also tried all versions of .NET Framework (2.0, 3.0, 3.5 4.0) but this does not change anything.
The development is done with VS2010 under Windows 7
Here are the code to test:
<pre>//Form1.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace PrintImageTest
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main ()
{
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault ( false );
Application.Run ( new Form1 () );
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PrintImageTest
{
public partial class Form1 : Form
{
public Form1 ()
{
InitializeComponent ();
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler ( printDocument1_PrintPage );
}
void printDocument1_PrintPage ( object sender, System.Drawing.Printing.PrintPageEventArgs e )
{
Bitmap Image = new Bitmap (@"C:\Temp\TestImage.jpg");
e.Graphics.DrawImage ( Image, 10,10 );
}
}
}
<br/>//Forms.Designer.cs
namespace PrintImageTest
{
partial class Form1
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose ( bool disposing )
{
if ( disposing && ( components != null ) )
{
components.Dispose ();
}
base.Dispose ( disposing );
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent ()
{
this.printPreviewControl1 = new System.Windows.Forms.PrintPreviewControl ();
this.printDocument1 = new System.Drawing.Printing.PrintDocument ();
this.SuspendLayout ();
//
// printPreviewControl1
//
this.printPreviewControl1.AutoZoom = false;
this.printPreviewControl1.Document = this.printDocument1;
this.printPreviewControl1.Location = new System.Drawing.Point ( 24, 32 );
this.printPreviewControl1.Name = "printPreviewControl1";
this.printPreviewControl1.Size = new System.Drawing.Size ( 401, 432 );
this.printPreviewControl1.TabIndex = 1;
this.printPreviewControl1.Zoom = 0.36783575705731392D;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF ( 6F, 13F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size ( 471, 508 );
this.Controls.Add ( this.printPreviewControl1 );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout ( false );
}
#endregion
private System.Windows.Forms.PrintPreviewControl printPreviewControl1;
private System.Drawing.Printing.PrintDocument printDocument1;
}
}
<br/>
//Programm.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace PrintImageTest
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main ()
{
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault ( false );
Application.Run ( new Form1 () );
}
}
}
</pre>
I would be very happy if someone could help with this.
Thank you in advance
pfotenh
|
|
|
|
|
Hi,
According to the PrintDocument class documentation, I would rather use
e.PageVisual = Image;
than
e.Graphics.DrawImage ( Image, 10,10 );
in your printDocument1_PrintPage method.
|
|
|
|
|