|
First, thank you for the reply, I did use Process.Start, it works ok, but I try to not using COM, but using .net technic. Any other way?
Thanks,
|
|
|
|
|
This is a new question, after I created a PDF file with data entry using iTextSharp, what is the best way to save it in the situation I need to bring back this PDf file.
Thanks in advance.
|
|
|
|
|
Dear Friends:
How can a program set the caret position in the text of the editable ComboBox? I set the ComboBox.SelectionStart and then ComboBox.SelectionLength. The caret for insertion automatically moved to the end of the selection, i.e. at the position, SelectionStart + SelectionLength. I want to move the caret to the beginning of the selection, i.e. at the position, SelectionStart. I could not find a property or method which can set the position of the caret. Thanks!
|
|
|
|
|
So I've decided to start diving into minor game programming and getting a better understanding of how it's done by making a few games this summer. The first is this clone of the Zombie Simulator that you might of seen by Kevan Davis. I'm not trying to be original mind you just to learn. I figured i'd be a pretty easy start but I've come to a dead stop.
I've managed to randomly create "buildings" but I'm having issues with my "Being" class being able to manipulate the outsider world. In the main program class "Zombie" I have my bitmap image set to protected which SHOULD allow for the Being class to manipulate it since it is a derived class from Zombie. So maybe someone can help me. What the hell am I doing wrong? BTW I know not all the methods are completely...but I must first be able to display the object before I continue onward. Below is all the code I've done. I hope it isn't to long.
using System; <br />
using System.Drawing; <br />
using System.Drawing.Drawing2D; <br />
using System.Collections; <br />
using System.ComponentModel; <br />
using System.Windows.Forms; <br />
using System.Data; <br />
<br />
namespace ZombiesSim<br />
{<br />
public class Zombie : System.Windows.Forms.Form <br />
{<br />
private System.ComponentModel.IContainer components;<br />
<br />
private bool _doBuffer = true;<br />
private int freeze, x, y, bwidth, bheight;<br />
private Color human, panichuman, zombie, wall;<br />
private int num = 1000;<br />
private int speed = 1;<br />
private Graphics g;<br />
private bool gxstart;<br />
private Being bee;<br />
public Bitmap world;<br />
protected int width, height;<br />
private Random rand = new Random();<br />
<br />
<br />
public Zombie() <br />
{ <br />
InitializeComponent(); <br />
<br />
human = Color.Purple;<br />
panichuman = Color.Pink;<br />
zombie = Color.Lime;<br />
wall = Color.DimGray;<br />
<br />
width = this.ClientSize.Width;<br />
height = this.ClientSize.Height;<br />
<br />
world = new Bitmap( width, height );<br />
g = Graphics.FromImage( world );<br />
gxstart = true;<br />
<br />
freeze = 0;<br />
}<br />
<br />
protected override void Dispose( bool disposing ) <br />
{ <br />
if( disposing ) <br />
{ <br />
if (components != null) <br />
{ <br />
components.Dispose(); <br />
} <br />
} <br />
base.Dispose( disposing ); <br />
} <br />
<br />
#region Windows Form Designer generated code <br />
private void InitializeComponent() <br />
{ <br />
this.components = new System.ComponentModel.Container(); <br />
this.SuspendLayout(); <br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); <br />
this.ClientSize = new System.Drawing.Size(666, 666); <br />
this.Name = "Zombie Simulation"; <br />
this.Text = "Zombie Simulation"; <br />
this.ResumeLayout(false);<br />
this.MaximizeBox = false;<br />
this.FormBorderStyle = FormBorderStyle.FixedDialog;<br />
this.Shown += new System.EventHandler(this.Zombie_Shown);<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.Run(new Zombie());<br />
}<br />
<br />
private void Zombie_Shown(object sender, EventArgs e)<br />
{<br />
}<br />
<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
if( world != null && gxstart == true )<br />
{<br />
<br />
g.Clear(Color.Black);<br />
<br />
for( int i = 0; i < 100; i++)<br />
{<br />
x = rand.Next( this.ClientSize.Width );<br />
y = rand.Next( this.ClientSize.Height );<br />
bwidth = rand.Next( 30, 90 );<br />
bheight = rand.Next( 30, 90 );<br />
g.FillRectangle( new SolidBrush( wall ), x, y, bwidth, bheight );<br />
}<br />
<br />
for( int i = 0; i < 30; i++)<br />
{<br />
x = rand.Next( this.ClientSize.Width );<br />
y = rand.Next( this.ClientSize.Height );<br />
bwidth = rand.Next( 40, 60 );<br />
bheight = rand.Next( 40, 60 );<br />
g.FillRectangle( new SolidBrush( wall ), x, y, bwidth, bheight );<br />
}<br />
<br />
gxstart = false;<br />
<br />
}<br />
<br />
setup();<br />
<br />
if(_doBuffer)<br />
{<br />
e.Graphics.DrawImageUnscaled( world ,0,0);<br />
}<br />
}<br />
<br />
public void setup()<br />
{<br />
bee = new Being();<br />
<br />
}<br />
<br />
protected override void OnPaintBackground(PaintEventArgs pevent) <br />
{ <br />
} <br />
<br />
protected override void OnSizeChanged(EventArgs e)<br />
{<br />
<br />
}<br />
}<br />
<br />
public class Being : Zombie<br />
{<br />
private int xpos, ypos, dir;<br />
private int type;<br />
private int active;<br />
private Random rand = new Random();<br />
private Color hue;<br />
<br />
public Being()<br />
{<br />
dir = rand.Next( 1, 4 );<br />
type = 1;<br />
active = 0;<br />
hue = Color.Purple;<br />
position();<br />
world.SetPixel( 5, 5, Color.Purple );<br />
}<br />
<br />
public int[] getposition()<br />
{<br />
int[] pos = { xpos, ypos };<br />
return pos;<br />
}<br />
<br />
public void position()<br />
{<br />
for( int j = 0; j < 100; j++ )<br />
{<br />
xpos = rand.Next( 1, width - 1);<br />
ypos = rand.Next( 1, height - 1);<br />
if( world.GetPixel( xpos, ypos ) == Color.Black )<br />
j = 100;<br />
}<br />
}<br />
<br />
<br />
<br />
public void infect( int x, int y )<br />
{<br />
if( x == xpos && y == ypos )<br />
type = 2;<br />
}<br />
<br />
public void infect()<br />
{<br />
hue = Color.Lime;<br />
type = 2;<br />
}<br />
<br />
public void uninfect()<br />
{<br />
hue = Color.Purple;<br />
type = 1;<br />
}<br />
<br />
public void look( int x, int y )<br />
{<br />
dir = rand.Next( 1, 4 );<br />
<br />
if( dir == 1 )<br />
y++;<br />
if( dir == 2 )<br />
x++;<br />
if( dir == 3 )<br />
y--;<br />
if( dir == 4 )<br />
x--;<br />
}<br />
<br />
public void move()<br />
{<br />
<br />
}<br />
}<br />
}
|
|
|
|
|
What do you percieve to be wrong ? If it doesn't compile, what line is the problem and what's the error ? If it does, then what is failing to happen, and what code is not doing what you'd hoped ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
It compiles but it is something with the "Being" class not being able to manipulate the "world" variable even though the permissions is set correctly. so I have no clue and since this is my first time manipulating graphics I'm not even sure if I'm initializing an instance of Being correctly.
|
|
|
|
|
I don't see which part of Being relates to graphics ?
You should not use get/setpixel in a game - too slow. The paint event is the right place to draw, Invalidate() is what you need to call to force a paint event. Beyond that, I'm not sure what you're hoping for, or what is wrong. What makes you think that 'world' can't manipulate 'being', if it tries to and it compiles, then it is, it's just not doing what you hope.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
what I'm hoping for is that each instance of Being will manipulate variable g (which is of type Graphics) to change where they are currently located on the screen. Unfortunately when I try to do a g.FillRectange( new SolidBrush( Color.Lime), 5, 5, 13, 13 ); for instance it won't add the rectangle to the screen. However if I do it in the OnPaint method with the exact same code it works. I'm also not trying to have the "world" manipulate "being." I'm trying to have "being" manipulate the "world" or in this case, now, the "g" which is the graphics on screen.
Everything compiles perfectly by the way. I hope that makes sense.
|
|
|
|
|
g = Graphics.FromImage( world ); will allow you to draw on the image held in 'world'. It will not display anything you draw there on the screen. The graphics object passed into a paint event cannot be stored for use later, and it's the only way to draw to the screen, except CreateGraphics, and that is a bad idea, as what you draw will be lost if the form is invalidated.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
so if I want to create the graphics for each "being" I'll need to manipulate them in the Paint event and not in the "Being" class? So instead of calling a g.FillRectangle( yada yada ) in the "Being" class i'll have to do that in the Paint event and use variables from a particular instance of "Being" to manipulate the graphics?
|
|
|
|
|
A common solution is to add code in your class which takes a graphics object, so you can iterate over your objects and have them draw themselves, in a paint event.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Sweet it seems to have worked! Thanks buddy. Now to figure out how to read a specific graphic pixel ha.
|
|
|
|
|
If you check out my image processing articles, they show the alternative way to access pixel data.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Bitmap bm = new Bitmap(@"c:\Hamtaro.jpg");
Graphics gr = Graphics.FromImage(bm);
gr.DrawString("Hello Graphics", new Font("Verdana", 10),
new SolidBrush(Color.Tomato), 1, 40);
What seems to be the problem
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
You don't clean up any resources ? You create a new brush instead of using the built in Brushes collection ?
What makes you think there is a problem ? I don't see any code that would display the bitmap with the text on it, and you're not saving it, so the original image will remain the same, only a bitmap in memory is modified.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Then how do you do it?? I even get an error on this line:
Bitmap bm = new Bitmap(@"c:\Hamtaro.jpg");
Error 1 Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'. An explicit conversion exists (are you missing a cast?)
And sorry, how do you save it eventually??
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Display it in a picturebox:
pictureBox1.Image = bm;
Save it to disk:
bm.Save(@"C:\Hamtaro_with_text.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
|
|
I'm a c programmer trying to convert my programs to c#. Many variables are global and require extern to access them. I'm a bit confused on how global variables are used in C#. How do a declare and used then in different dll's
Brian
|
|
|
|
|
There are no global variables in C#. C to C# is a huge jump, because C does not have classes and C# cannot work without them. If you must have globals, create a class with public static properties on it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
How do you suggest I deal with 2-d arrays that must accessed by a number of subroutines (methods in C# - if I read correctly). In some cases the data must be passed to nested methods. global vars seem like the best option. If I read what you are saying correctly. I can create a method that contains a struct which would hold the data,declare it static then refer to it anywhere. Am I right?
Brian
|
|
|
|
|
Yo can create a property which IS the array, and access it anywhere. I'd be more inclined to pass the data through the subroutines, but it's a matter of style. Globals are ugly, but they do no harm, in and of themselves, if they are not misused.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks, I think I now know how to handle my code. Since it's already written for globals I'll use the method approach. Once I have it running I'll rewrite it passing the functions. The irony here is that I was a fortran programmer who had to leardn C to write this code, now I am moving on once again....after this I plan to learn event driven programing. Good grief, I might not survive that!
I'm in the market for good reference books. I thought for sure someone would come up with a good book that explains(ilustrates through examples) how to move from c to c#. If there is, I can't find it.
Brian
|
|
|
|
|
To add to what Christian said. If you are converting your application to C# and are taking advantage of all that OO goodness then you should be aware that in most cases (the vast majority of cases) the feeling that you need a global is an indication of a poor design.
|
|
|
|
|
yeah, I was holding back, but that's what I meant by 'if you must have globals'. Delegates are a good alternative, they let you tell just the other classes you need to, that something has changed.
If only C# had friend classes, things could be a lot tighter than they are.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
I want to show combinations of various factors used in the DOE experiment i.e. in first page I ask the user to choose 6 factors and 2 levels for each factor. So all combinations of these levels come down to 64. I want to show all these combinations in the datagrid in the next page.
For e.g.: Suppose A is the first factor with two levels a1 n a2 and B is the 2nd factor with levels b1 n b2, then all the combinations of the levels will be 4 i.e. a1 b1, a1 b2, a2 b1 and a2 b2. So datagrid will have 2 colums and 4 rows to display these combinations.
I have prepared a new page with a datagrid but I am not able to display all the combinations in the datagrid table.
Thanks.
-- modified at 8:12 Monday 21st May, 2007
|
|
|
|