Click here to Skip to main content
15,896,278 members
Home / Discussions / C#
   

C#

 
GeneralECMA Pin
Sam Hobbs25-Jul-00 16:42
Sam Hobbs25-Jul-00 16:42 
GeneralRe: ECMA Pin
Ravi Shankar26-Jul-00 18:50
Ravi Shankar26-Jul-00 18:50 
GeneralRe: ECMA Pin
- V -14-Jan-01 17:40
- V -14-Jan-01 17:40 
GeneralRe: ECMA Pin
Salil Khedkar27-Oct-04 22:58
Salil Khedkar27-Oct-04 22:58 
GeneralCool or Uncool Pin
Member 222719-Jul-00 14:50
Member 222719-Jul-00 14:50 
GeneralRe: Cool or Uncool Pin
mark_bar19-Jul-00 21:29
mark_bar19-Jul-00 21:29 
GeneralRe: Cool or Uncool Pin
Chris Maunder20-Jul-00 11:10
cofounderChris Maunder20-Jul-00 11:10 
GeneralRe: Cool or Uncool Pin
Keith Hill20-Jul-00 13:04
Keith Hill20-Jul-00 13:04 
C# is definitely cool to program in. BTW, you won't need to drop back to VB to do UI. C# (as well as managed C++) gets the same RAD support that VB has in VS.NET. Check out the following code I wrote in about a half hour to display three jpg images. Note, this code probably wouldn't be too hard to duplicate in VB, but try this in VC++ using Win32 API Smile | :) NOTE: the use of XML comments. The compiler supports stripping these out into an XML document like so:

<makefile>
all: MyPhotoAlbum.exe

MyPhotoAlbum.exe: MyPhotoAlbum.cs
csc /debug+ /doc:MyPhotoAlbum.xml /t:winexe \
MyPhotoAlbum.cs /r:system.dll \
/r:system.drawing.dll /r:System.WinForms.dll \
/r:System.Data.dll /r:Microsoft.Win32.Interop.dll


namespace CSharpApp
{
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.WinForms;
using System.Data;

///
/// Class representing my application's main window
///

public class MainWindow : System.WinForms.Form
{
/// Required designer variable
private System.ComponentModel.Container components;
private System.WinForms.Button m_button3;
private System.WinForms.Button m_button2;
private System.WinForms.Button m_button1;
///
/// IVar to hold reference of bitmap to paint
///

private System.Drawing.Bitmap m_bitmap;
private System.Drawing.Bitmap m_bitmap1;
private System.Drawing.Bitmap m_bitmap2;
private System.Drawing.Bitmap m_bitmap3;
private System.Drawing.Point m_orgBitmap;

public MainWindow()
{
//
// Required for Win Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after
// InitializeComponent call
//
try
{
m_bitmap1 = new Bitmap(@"c:\images\A.jpg");
m_bitmap2 = new Bitmap(@"c:\images\B.jpg");
m_bitmap3 = new Bitmap(@"c:\images\C.jpg");
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Bummer!",
MessageBox.IconHand);
}
m_orgBitmap = new Point(10, 60);
}

///
/// Clean up any resources being used
///

public override void Dispose()
{
base.Dispose();
components.Dispose();
}

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor
///

private void InitializeComponent()
{
this.components =
new System.ComponentModel.Container();
this.m_button1 = new System.WinForms.Button();
this.m_button2 = new System.WinForms.Button();
this.m_button3 = new System.WinForms.Button();

this.AutoScaleBaseSize =
new System.Drawing.Size(5, 13);
this.Text = "My Photo Album";
this.BackColor = System.Drawing.Color.Blue;
this.ClientSize = new System.Drawing.Size(586, 445);

m_button1.Location = new System.Drawing.Point(8, 8);
m_button1.BackColor =
System.Drawing.SystemColors.ControlLight;
m_button1.Size = new System.Drawing.Size(75, 23);
m_button1.TabIndex = 0;
m_button1.Text = "Bitmap 1";
m_button1.AddOnClick(
new System.EventHandler(ButtonClickHandler));

m_button2.Location =
new System.Drawing.Point(104, 8);
m_button2.BackColor =
System.Drawing.SystemColors.ControlLight;
m_button2.Size = new System.Drawing.Size(75, 23);
m_button2.TabIndex = 1;
m_button2.Text = "Bitmap 2";
m_button2.AddOnClick(
new System.EventHandler(ButtonClickHandler));

m_button3.Location =
new System.Drawing.Point(200, 8);
m_button3.BackColor =
System.Drawing.SystemColors.ControlLight;
m_button3.Size = new System.Drawing.Size(75, 23);
m_button3.TabIndex = 2;
m_button3.Text = "Bitmap 3";
m_button3.AddOnClick(
new System.EventHandler(ButtonClickHandler));

this.Controls.Add(m_button1);
this.Controls.Add(m_button2);
this.Controls.Add(m_button3);
}

protected void ButtonClickHandler(object sender,
System.EventArgs e)
{
// Rectangles to store regions to invalidate
Rectangle rectPrev =
new Rectangle(m_orgBitmap, new Size(0,0));
Rectangle rectCurrent =
new Rectangle(m_orgBitmap, new Size(0,0));

// Grab current bitmap's size
if (m_bitmap != null)
rectPrev.Size = m_bitmap.Size;

// Select appropriate bitmap based on the sender
if (sender == m_button1) {
m_bitmap = m_bitmap1;
}
else if (sender == m_button2) {
m_bitmap = m_bitmap2;
}
else {
m_bitmap = m_bitmap3;
}

// Grab new bitmap's size
if (m_bitmap != null)
rectCurrent.Size = m_bitmap.Size;

// Create region, union of both rectangles
Region region = new Region(rectPrev);
region.Union(rectCurrent);

// Invalidate the combined regions
this.Invalidate(region);
}

protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;

// Draw background
g.FillRectangle(new SolidBrush(Color.Blue),
e.ClipRectangle);

//Render bitmap image
if (m_bitmap != null)
g.DrawImage(m_bitmap, m_orgBitmap.X,
m_orgBitmap.Y);
}

// The main entry point for the application.
public static void Main(string[] args)
{
Application.Run(new MainWindow());
}
}
}
GeneralRe: Cool or Uncool Pin
Keith Hill20-Jul-00 13:06
Keith Hill20-Jul-00 13:06 
GeneralRe: Cool or Uncool Pin
Alvaro Mendez26-Jul-00 8:23
Alvaro Mendez26-Jul-00 8:23 
GeneralRe: Cool or Uncool Pin
Benedict Verheyen20-Jul-00 13:44
sussBenedict Verheyen20-Jul-00 13:44 
GeneralRe: Cool or Uncool Pin
Keith Hill21-Jul-00 20:15
Keith Hill21-Jul-00 20:15 
GeneralRe: Cool or Uncool Pin
tmt19-Sep-00 13:27
tmt19-Sep-00 13:27 
GeneralAn explaination Pin
kaenneth28-Jul-00 14:00
kaenneth28-Jul-00 14:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.