C#_hw9_S17.doc
Modify AnimatedBall on Chapter 13. Instead of drawing a ball, you need to draw a car. Let the car draw around. When the car reached the right end, make a turn and draw downward. When it reached the bottom, draw to the left, then go upward, …
Change the name of three buttons Go (resume), Stop (suspend), and Quit (Abort)
xid-1979246_1.gif
xid-1979247_1.gif
xid-1979248_1.gif
xid-1979249_1.gif
AnimateBall.cs
//Copyright (c) 2002, Art Gittleman
//This example is provided WITHOUT ANY WARRANTY
//either expressed or implied.
/* Animates a ball. Uses a thread to allow the system to
* continue other processing.
*/
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
public class AnimateBall : Form {
private int x, y;
private Button suspend = new Button();
private Button resume = new Button();
private Button abort = new Button();
Thread t;
public AnimateBall() {
BackColor = Color.White;
Text = "Animate Ball";
abort.Text = "Abort";
suspend.Text = "Suspend";
resume.Text = "Resume";
int w = 20;
suspend.Location = new Point(w, 200);
resume.Location = new Point(w += 10 + suspend.Width, 200);
abort.Location = new Point(w += 10 + resume.Width, 200);
abort.Click += new EventHandler(Abort_Click);
suspend.Click += new EventHandler(Suspend_Click);
resume.Click += new EventHandler(Resume_Click);
Controls.Add(suspend);
Controls.Add(resume);
Controls.Add(abort);
x = 50; y = 50;
t = new Thread(new ThreadStart(Run));
t.Start();
}
protected void Abort_Click(object sender, EventArgs e) {
t.Abort();
}
protected void Suspend_Click(object sender, EventArgs e) {
t.Suspend();
}
protected void Resume_Click(object sender, EventArgs e) {
t.Resume();
}
protected override void OnPaint( PaintEventArgs e ) {
Graphics g = e.Graphics;
g.FillEllipse(Brushes.Red, x ,y, 40 ,40);
base.OnPaint(e);
}
public void Run() {
int dx=9, dy=9;
while (true) {
for(int i=0; i<10; i++) {
x+=dx;
y+=dy;
Invalidate();
Thread.Sleep(100);
}
dx = -dx; dy = -dy;
}
}
public static void Main( ) {
Application.Run(new AnimateBall());
}
}
C#_hw8_S17_update.doc
Modify from MenuDialog to create a simple text editor. You need to add [STAThread]
Before its Main method to make it work.
In File menu, add option like New, Open, Save, Save As,Close, and Exit.
When the user selects Save As, display a SaveFileDialog to let the user to select a filename and whatever in the textbox should be saved to this file.
When the user selects Save, display a SaveFileDialog if the file has not been opened (created after the user clicked New or Close).
Both objects from OpenFileDialog and SaveFileDialog has a property called FileName. Define an instance variable of String type call ...
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
1. C#_hw9_S17.doc
Modify AnimatedBall on Chapter 13. Instead of drawing a ball,
you need to draw a car. Let the car draw around. When the car
reached the right end, make a turn and draw downward. When it
reached the bottom, draw to the left, then go upward, …
Change the name of three buttons Go (resume), Stop (suspend),
and Quit (Abort)
xid-1979246_1.gif
xid-1979247_1.gif
xid-1979248_1.gif
xid-1979249_1.gif
AnimateBall.cs
//Copyright (c) 2002, Art Gittleman
//This example is provided WITHOUT ANY WARRANTY
//either expressed or implied.
/* Animates a ball. Uses a thread to allow the system to
* continue other processing.
*/
2. using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
public class AnimateBall : Form {
private int x, y;
private Button suspend = new Button();
private Button resume = new Button();
private Button abort = new Button();
Thread t;
public AnimateBall() {
BackColor = Color.White;
Text = "Animate Ball";
abort.Text = "Abort";
suspend.Text = "Suspend";
resume.Text = "Resume";
3. int w = 20;
suspend.Location = new Point(w, 200);
resume.Location = new Point(w += 10 + suspend.Width,
200);
abort.Location = new Point(w += 10 + resume.Width, 200);
abort.Click += new EventHandler(Abort_Click);
suspend.Click += new EventHandler(Suspend_Click);
resume.Click += new EventHandler(Resume_Click);
Controls.Add(suspend);
Controls.Add(resume);
Controls.Add(abort);
x = 50; y = 50;
t = new Thread(new ThreadStart(Run));
t.Start();
}
5. x+=dx;
y+=dy;
Invalidate();
Thread.Sleep(100);
}
dx = -dx; dy = -dy;
}
}
public static void Main( ) {
Application.Run(new AnimateBall());
}
}
C#_hw8_S17_update.doc
Modify from MenuDialog to create a simple text editor. You
need to add [STAThread]
Before its Main method to make it work.
In File menu, add option like New, Open, Save, Save As,Close,
and Exit.
When the user selects Save As, display a SaveFileDialog to let
the user to select a filename and whatever in the textbox should
be saved to this file.
6. When the user selects Save, display a SaveFileDialog if the file
has not been opened (created after the user clicked New or
Close).
Both objects from OpenFileDialog and SaveFileDialog has a
property called FileName. Define an instance variable of String
type called filename to hold file name after an OpenFileDialog
or SaveFileDialog is created. When the user clicks Save and
filename is null, display SaveFileDialog.
When New and Close is selected, simply set textbox as empty
string like textBox1.Text=”” and set filename as null.
Add a menu called Edit with three items like Cut, Copy, Paste
textBox1.selectedText returns the selected text from the textbox
Clipboard.SetText(textBox1.SelectedText) adds selectedText to
Clipboard
Clipboard.GetText() returns what is in the clipboard.
When the user clicks cut or copy, set the clipboard with the text
selected
When paste is clicked, set textBox1.Text as
textBox1.Text.Substring(0, textBox1.SelectionStart) + what is
in the clipboard +
textBox1.Text.Substring(textBox1.SelectionStart +
textBox1.SelectionLength);
When cut is clicked, it is almost same as above except “what is
in the clipboard” will be empty string
Add another menu like Help with one or two option like who
created the editor and version etc.
Add one line like: text.Dock = DockStyle.Fill;to make the
7. textarea stretch to the whole window
MenuDialog.cs
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
public class MenuDialog : Form {
// Create control
TextBox text = new TextBox();
public MenuDialog() {
// Configure form
Size = new Size(500,200);
8. Text = "Menus and Dialogs";
// Configure text box
text.Size = new Size(450,120);
text.Multiline = true;
text.ScrollBars = ScrollBars.Both;
text.WordWrap = false;
text.Location = new Point(20,20);
// Configure file menu
MenuItem fileMenu = new MenuItem("File");
MenuItem open = new MenuItem("Open");
open.Shortcut = Shortcut.CtrlO;
MenuItem save = new MenuItem("Save");
save.Shortcut = Shortcut.CtrlS;
fileMenu.MenuItems.Add(open);
fileMenu.MenuItems.Add(save);
9. // Configure feedback menu
MenuItem feedbackMenu = new MenuItem("Feedback");
MenuItem message = new MenuItem("Message");
message.Shortcut = Shortcut.CtrlM;
feedbackMenu.MenuItems.Add(message);
// Configure format menu
MenuItem formatMenu = new MenuItem("Format");
MenuItem font = new MenuItem("Font");
font.Shortcut = Shortcut.CtrlF;
formatMenu.MenuItems.Add(font);
// Configure main menu
MainMenu bar = new MainMenu();
Menu = bar;
bar.MenuItems.Add(fileMenu);
bar.MenuItems.Add(feedbackMenu);
bar.MenuItems.Add(formatMenu);
10. // Add control to form
Controls.Add(text);
// Register event handlers
open.Click += new EventHandler(Open_Click);
save.Click += new EventHandler(Save_Click);
message.Click += new EventHandler(Message_Click);
font.Click += new EventHandler(Font_Click);
}
// Handle open menu item
protected void Open_Click(Object sender, EventArgs e) {
OpenFileDialog o = new OpenFileDialog();
if(o.ShowDialog() == DialogResult.OK) {
Stream file = o.OpenFile();
StreamReader reader = new StreamReader(file);
char[] data = new char[file.Length];
11. reader.ReadBlock(data,0,(int)file.Length);
text.Text = new String(data);
reader.Close();
}
}
// Handle save menu item
protected void Save_Click(Object sender, EventArgs e) {
SaveFileDialog s = new SaveFileDialog();
if(s.ShowDialog() == DialogResult.OK) {
StreamWriter writer = new StreamWriter(s.OpenFile());
writer.Write(text.Text);
writer.Close();
}
}
// Handle message menu
protected void Message_Click(Object sender, EventArgs e) {
12. MessageBox.Show
("You clicked the Message menu", "My message");
}
// Handle font menu
protected void Font_Click(Object sender, EventArgs e) {
FontDialog f = new FontDialog();
if(f.ShowDialog() == DialogResult.OK)
text.Font = f.Font;
}
public static void Main() {
Application.Run(new MenuDialog());
}
}
13. LIT331/332 Brief Writing Assignments Overview and Standards
You will be required to submit a brief writing assignment each
week during Seminars One through Five. The writing topic will
be provided during that seminar.
Note that you should be taking notes as the seminar progresses
so that by the end you’ve got a rather clear path toward the
writing assignment.
Basic standards:
· APA formatting (title page, double-spaced, citations).
· Thesis statement should reflect the writing prompt.
· Organize these as basic essays—set up your point in an
introduction paragraph, give three supporting points that rely on
the readings for examples, and conclude with a clear summation
of your larger argument/response to the question.
· Supporting details are required from the readings. Note that
since these are relatively short assignments, you don’t want to
waste a lot of time summarizing the texts—assume your
audience has read them and get to the point quickly. Quotations
should be used as support, rather than content.
· The final length should be approximately 1 ½ - 2 pages (350-
500 words).
· Standard English is required.
· No first person.
LIT331/332 Brief 032310