|
// This source code is provided as C# sample to use the XCD Library.
// Copyright © 2011 MSB LLC. All rights reserved.
using System;
using System.Drawing;
using System.Windows.Forms;
using XCD;
using Microsoft.VisualBasic.Compatibility.VB6; // IPicture support
namespace XCD_Client_CS
{
public partial class frmXCDClient : Form
{
public frmXCDClient()
{
InitializeComponent();
}
private void XCD_Client_CS_Load(object sender, EventArgs e)
{
objCollection = new XCD.Collection();
objCar = new XCD.Car();
cboTagName.Items.Add("Year");
cboTagName.Items.Add("Make");
cboTagName.Items.Add("Model");
cboTagName.Items.Add("Submodel");
cboTagName.Items.Add("Type");
cboTagName.Items.Add("Price");
cboTagName.Items.Add("Country");
cboTagName.Items.Add("Length");
cboTagName.Items.Add("Width");
cboTagName.Items.Add("Height");
cboTagName.Items.Add("Weight");
cboTagName.Items.Add("Power");
cboTagName.Items.Add("Fuel");
cboTagName.Items.Add("Clearance");
cboTagName.Items.Add("Tank Volume");
cboTagName.SelectedIndex = 0;
btnGetPictureTitle.Enabled = false;
btnShowPicture.Enabled = false;
btnGetValue.Enabled = false;
}
private void btnSelectCARFile_Click(object sender, EventArgs e)
{
int nItemCount;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "CAR Files (*.car)|*.car";
ofd.RestoreDirectory = true;
ofd.Title = "Select Car Collection File";
if (ofd.ShowDialog() == DialogResult.OK)
{
objCollection.FFN = ofd.FileName;
if (objCollection.IsCarFile())
{
nItemCount = objCollection.GetCount();
txtFFN.Text = ofd.FileName;
txtCollectionTitle.Text = objCollection.GetTitle();
txtCollectionItemCount.Text = nItemCount.ToString();
txtCollectionVersion.Text = objCollection.GetVersion();
txtCollectionXCDVersion.Text =
objCollection.GetXCDVersion();
nudItem.Minimum = 0;
nudItem.Maximum = nItemCount - 1;
btnGetPictureTitle.Enabled = true;
btnShowPicture.Enabled = true;
btnGetValue.Enabled = true;
}
else
MessageBox.Show("The file is not a CAR file!",
"XCD_CS_Client");
}
}
private void btnGetPictureTitle_Click(object sender, EventArgs e)
{
txtPictureTitle.Text = objCar.GetPictureTitle(
(ushort)nudItem.Value);
}
private void btnShowPicture_Click(object sender, EventArgs e)
{
stdole.IPicture picture = null;
int intHeight;
int intWidth;
double dblScaleX;
int intPictureBoxHeight;
picture = objCar.GetPicture((ushort)nudItem.Value);
// Microsoft.VisualBasic.Compatibility.VB6 does not have
// TwipsPerPixelX (Y) properties like in VB so function
// GetTwipsPerPixel is added.
intHeight = picture.Height / (int)GetTwipsPerPixel("X");
intWidth = picture.Width / (int)GetTwipsPerPixel("Y");
dblScaleX = (double)picCarImage.Width / (double)intWidth;
intPictureBoxHeight = (int)(dblScaleX * intHeight);
// Center vertically.
picCarImage.Top = picCarImage.Location.Y +
(picCarImage.Height - intPictureBoxHeight) / 2;
picCarImage.Height = intPictureBoxHeight;
picCarImage.SizeMode = PictureBoxSizeMode.StretchImage;
picCarImage.Image = Support.IPictureToImage(picture);
}
private void btnGetValue_Click(object sender, EventArgs e)
{
txtTagValue.Text = objCar.GetValue((ushort)nudItem.Value,
cboTagName.Text);
}
private void lnkSite_Clicked(object sender,
LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(
"www.myscreensaverbuilder.com/CE.htm");
}
private double GetTwipsPerPixel(string strDirection)
{
const int LOGPIXELSX = 88;
const int LOGPIXELSY = 90;
const int intTwipsPerInch = 1440;
int intIndex;
int intPixelsPerInch;
double dblTwipsPerPixel;
Graphics gfx = this.CreateGraphics();
IntPtr hDC = gfx.GetHdc();
if (strDirection == "X")
intIndex = LOGPIXELSX;
else if (strDirection == "Y")
intIndex = LOGPIXELSY;
else
intIndex = LOGPIXELSX;
// Get number of pixels per logical inch along the screen width or
// height.
intPixelsPerInch = GetDeviceCaps(hDC, intIndex);
dblTwipsPerPixel = (double)intTwipsPerInch /
(double)intPixelsPerInch;
gfx.ReleaseHdc(hDC);
return dblTwipsPerPixel;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.