|
Don't you have the driver that goes with your printer? Try this[^].
BTW: I fail to see how an image would need to be converted into an ASCII string.
And what would you do if you had such string? It would print as text anyway.
|
|
|
|
|
I actually don't have access to the printer at the moment to be able to test and the thing is that the printer can handle either the .PCX file format or ASCII format. According to the project specifications I must convert the .BMP-file I have to ASCII.
|
|
|
|
|
Then you should hunt for the printer's documentation. Although I still think getting the proper driver is the right way to go.
|
|
|
|
|
ASCII is text. So define how this image is supposed to be "converted to ASCII". Are you talking about "ASCII art"? Are you saying that the printer understands some bitmap format and the image has to be converted into a string of commands that the printer understands in order to printer the image?
|
|
|
|
|
A bitmap consist of a header telling wich color depth it has how large it is and the data describing the image etc, etc. This is what is supposed to be sent to the printer coverted to ASCII characters. I'm not talking about ASCII art, and it is not "commands" which tells the printer what to do, it is just plain data that the printer interprets as an image.
At the moment I haven't got the actual printer model and hence no manual. I thougth that this was a common problem for which there are quite a few solutions to?!
|
|
|
|
|
Mats Eurén wrote: and it is not "commands" which tells the printer what to do, it is just plain data that the printer interprets as an image.
How do you think the printer knows what's an image and what isn't?? You have to format the data with the correct COMMAND CODES, which as specific to each printer, to tell it that the data that's coming is an image and how to render it. But, without the manual/documentation on the command codes the printer understands, you'll find it impossible to do this.
Mats Eurén wrote: I thougth that this was a common problem for which there are quite a few solutions to?!
No, actually, that is a very old method of getting the printer to print an image. Today, it's done through printer drivers that handle images automatically. You basically draw the image to a drawing surface that represents the page, then the printer driver converts that image into a stream of command codes and data that the printer understands.
|
|
|
|
|
Alright, I'll have to get more basic facts about the printer first then?! Thanks anyway.
|
|
|
|
|
I want to insert a table from a MySQL database with a DataGridView, but I have the common problem with IndexOutOfRange, if someone can help me with my code, to correct the errors. Sometime is working ok, sometime not.
private void bWorkGridView_DoWork(object sender, DoWorkEventArgs e)
{
initGridView();
MySqlCommand command = conexiuneSQL.CreateCommand();
command.CommandText = "select * from preluari";
mySqlDataAdapter1 = new MySqlDataAdapter(command);
DataSet ds = new DataSet();
mySqlDataAdapter1.Fill(mySqlDataTable1);
binding.DataSource = mySqlDataTable1;
if (GridView.InvokeRequired)
{
GridView.Invoke(new MethodInvoker(delegate { Thread.Sleep(200); GridView.DataSource = binding;}));
}
}
I'm working with BackgroundWorker to update the DataGridView and for connections I'm using dotconnect
|
|
|
|
|
memorexr wrote: I have the common problem
what do you mean?
memorexr wrote: IndexOutOfRange
in what line exactly?
memorexr wrote: Thread.Sleep(200);
why do you want the main thread to sleep? it doesn't make sense to me.
memorexr wrote: binding.DataSource
what is binding? is it already in use? is your code running fine once, then failing later?
if so, you should unbind before having some other thread or BGW modifying it.
|
|
|
|
|
Common problem because i've found many post on web with this kind of problem.
I will attach a picture with the error. binding is from dotconnect framework.The error is not from initGridView().
private void initGridView()
{
GridView.BackgroundColor = Color.AliceBlue;
GridView.AllowUserToAddRows = false;
GridView.AllowUserToDeleteRows = false;
GridView.AllowUserToResizeColumns = false;
GridView.AllowUserToResizeRows = false;
GridView.ReadOnly = true;
GridView.RowsDefaultCellStyle.BackColor = Color.LightGray;
GridView.AlternatingRowsDefaultCellStyle.BackColor = Color.DarkGray;
}
error picture
|
|
|
|
|
memorexr wrote: The error is not from initGridView()
really?
each of these statements touches a GUI Control and therefore MUST be executed on the main thread.
You call initGridView() from within a method whose name suggests it is run by a BackgroundWorker, hence on another thread. Big mistake. Read the article I already provided.
BTW: why call initGridView() at the start of DoWork? Can't you call it before starting the BGW, it doesn't take long to execute!
|
|
|
|
|
Done, I've moved the initGridView in the main thread on GUI init and I've deleted that Thread.Sleep(), but nothing...the same problem.
|
|
|
|
|
So you have acted upon half of my remarks in my initial response.
|
|
|
|
|
I've tried everything that I know,but nothing...
|
|
|
|
|
what line throws the exception?
|
|
|
|
|
Directly from the main()
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormTester());
}
If I'm not using the DataGrid everything is working perfect
|
|
|
|
|
The exception gives a full stack traceback, with all the methods leading up to it. When using a debug build they also mention line numbers, the very first line number is where it actually blows up. That is where you should look.
And you said IndexOutOfRange before, now you're saying NullReference. What is it?
|
|
|
|
|
If I'm using the debugger from VS 2010, when the error appears in the editor I see the error with NullReference, I can't track the exact line where the error appears.
|
|
|
|
|
use a debug build, use try-catch blocks, look at each Exception.ToString() that gets thrown, watch for line numbers, increase the observability by adding log statements, that should be sufficient to solve any problem.
Others will tell you to set breakpoints, and/or run in single-step. I'm not saying that.
One more thing: don't write hundreds of lines of code at once, start small and make sure it works perfectly before you expand on it. Once you have several bugs coming together it may be very hard to figure out what is wrong. When you have something that works pretty well, expand on it by adding a dozen lines, then make sure those work fine too. Etc.
|
|
|
|
|
memorexr wrote: initGridView();
This is probably where you are getting the index error.
You will need to post the code for this method.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Abhinav S wrote: This is probably where you are getting the error
No need to guess or gamble.
People should learn to read the information an exception provides. Starting with line numbers (I am assuming a debug build of course).
|
|
|
|
|
hi everyone, What I'm trying to do with the below code is; I want to run the doUpdate() method on a seperate thread in order to keep the responsiveness of the main form. It doesn't work. Could you tell me where I stuck? please
private void Form1_Load(object sender, EventArgs e)
{ Thread thd = new Thread(new ThreadStart(bilgiGuncelle));
thd.Start();
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (InvokeRequired) this.Invoke(new dlgUpdate(doUpdate));
else doUpdate();
}
private void doUpdate()
{
}
|
|
|
|
|
I have not yet read your code and so you may be lucky enough to get an answer anyway but IMO you will be more likely to get help if you edit your question to expand on what 'It doesn't work.' means.
Do you get an exception? Does it give unexpected results? Does the UI become unresponsive?
In what way does it not work?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: In what way does it not work?
When I call the doUpdate() code from Form's load event or anywhere else, update process is done. When I call the same method within a thread, it doesn't.
|
|
|
|
|
A lot of information is missing to understand what is going on here, such as:
- what timer you use
- what dlgUpdate might be
- what exactly is happening in doUpdate().
If your timer is a System.Windows.Forms.Timer (as your interval comment may suggest), then you should know it always "ticks" on the main thread, so the InvokeRequired line doesn't make sense, and the GUI behavior will be hampered by whatever doUpdate() actually does (such as waiting for a DB response).
If you were to switch to another kind of timer, it would not make sense to have its tick handler do an Invoke the way you did it, as that too would cause everything to run on the main thread. What you probably should do is:
- start a thread that loops a combination of doUpdate and a Thread.Sleep
- have doUpdate gather information and not touch the GUI
- then Invoke a method to update the GUI (that must run on the main thread, see here[^].
[ADDED]
You should have a look at BackgroundWorker, as that is pretty much tailored to what you probably want: put the loop (fetchData+sleep) in DoWork, and use ReportProgress to update the GUI.
[/ADDED]
|
|
|
|