|
if ( whatever is IEnumerable )
{
// Iterate the items with foreach
}
else
{
// Normal
}
|
|
|
|
|
Hii i am writing a code to make the glass effect on windows form. Well the code works fine on vista but my target is on windows xp. I have copyed all the dll's that are reqired and when i debug i am getting an error "DLL NOT FOUND EXCEPTION UNHANDILED".
Here is the code that i am using:-
-----------------------------------------------------------------------------------------------------------------------------
This is the class where i import dwmapi dll.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace welcome_page
{
class VistaGlassEffect
{
internal class VistaApi
{
[DllImport("dwmapi.dll")]
internal static extern void DwmExtendFrameIntoClientArea(System.IntPtr hWnd, ref Margins pMargins);
[DllImport("dwmapi.dll")]
internal static extern void DwmIsCompositionEnabled(ref bool isEnabled);
internal struct Margins
{
public int Left, Right, Top, Bottom;
}
// consts for wndproc
internal const int WM_NCHITTEST = 0x84;
internal const int HTCLIENT = 1;
internal const int HTCAPTION = 2;
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
This the form where i call this class "VistaGlassEffect"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;
using System.Diagnostics;
using System.Drawing.Drawing2D;
namespace welcome_page
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.FitGlass();
}
Video video;
private welcome_page.VistaGlassEffect.VistaApi.Margins marg;
private Rectangle topRect = Rectangle.Empty;
private Rectangle botRect = Rectangle.Empty;
private Rectangle lefRect = Rectangle.Empty;
private Rectangle rigRect = Rectangle.Empty;
private void FitGlass()
{
// If DWM is not enabled then get out
if (!this.IsGlassEnabled())
{
return;
}
// Set the Margins to their default values
marg.Top = 600; // extend from the top
marg.Left = 400; // not used in this sample but could be
marg.Right = 200; // not used in this sample but could be
marg.Bottom = 860;// not used in this sample but could be
this.Paint += new PaintEventHandler(this.Form1_Paint);
// call the function that gives us glass,
// passing a reference to our inset Margins
welcome_page.VistaGlassEffect.VistaApi.DwmExtendFrameIntoClientArea(this.Handle, ref marg);
}
private void apply()
{
this.Paint -= new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.RecreateHandle(); //needed if changing on the fly
this.FitGlass();
}
private bool IsGlassEnabled()
{
//if (Environment.OSVersion.Version.Major < 6)
//{
// Debug.WriteLine("How about trying this on Vista?");
// return false;
//}
//Check if DWM is enabled
bool isGlassSupported = false;
------welcome_page.VistaGlassEffect.VistaApi.DwmIsCompositionEnabled(ref isGlassSupported);---Here Error OCCURS.
return isGlassSupported;
}
// Alpha-blending Paint after the glass extension
// this seems better than the winforms transparency approach because here we can click on the glass!
private void Form1_Paint(object sender, PaintEventArgs e)
{
// black brush for Alpha transparency
SolidBrush blackBrush = new SolidBrush(Color.Black);
Graphics g = e.Graphics;
if (this.IsGlassEnabled())
{
// setup the rectangles
topRect = new Rectangle(0, 0, this.ClientSize.Width, marg.Top);
lefRect = new Rectangle(0, 0, marg.Left, this.ClientSize.Height);
rigRect = new Rectangle(this.ClientSize.Width - marg.Right, 0, marg.Right, this.ClientSize.Height);
botRect = new Rectangle(0, this.ClientSize.Height - marg.Bottom, this.ClientSize.Width, marg.Bottom);
// Fill Rectangles
g.FillRectangle(blackBrush, topRect);
g.FillRectangle(blackBrush, lefRect);
g.FillRectangle(blackBrush, rigRect);
g.FillRectangle(blackBrush, botRect);
}
blackBrush.Dispose();
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == welcome_page.VistaGlassEffect.VistaApi.WM_NCHITTEST // if this is a click
&& m.Result.ToInt32() == welcome_page.VistaGlassEffect.VistaApi.HTCLIENT // ...and it is on the client
&& this.IsOnGlass(m.LParam.ToInt32())) // ...and specifically in the glass area
{
m.Result = new IntPtr(welcome_page.VistaGlassEffect.VistaApi.HTCAPTION); // lie and say they clicked on the title bar
}
}
private bool IsOnGlass(int lParam)
{
// sanity check
if (!this.IsGlassEnabled())
{
return false;
}
// get screen coordinates
int x = (lParam << 16) >> 16; // lo order word
int y = lParam >> 16; // hi order word
// translate screen coordinates to client area
Point p = this.PointToClient(new Point(x, y));
// work out if point clicked is on glass
if (topRect.Contains(p) || lefRect.Contains(p) || rigRect.Contains(p) || botRect.Contains(p))
{
return true;
}
return false;
}
void buttn()
{
}
private void Form2_Load(object sender, EventArgs e)
{
int width = panel1.Width;
int height = panel1.Height;
System.Uri u = new Uri(@"F:\Documents\Viswa Teja\Documents\C2\teja.avi");
video = Video.FromUrl(u);
video.Owner = panel1;
video.Play();
panel1.Size = new Size(width, height);
//this.apply();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
Please kindly help me.
|
|
|
|
|
Is it possible that your Vista is a 64 bit version?
You can't mix 64 bit apps with 32 bit dlls.
[edit] I should learn to read ....... just ignore this post
Greetings
Covean
modified on Wednesday, November 4, 2009 8:41 AM
|
|
|
|
|
You asked this question here[^] and were told you couldn't do this using dwmapi.dll.
This is a Vista+ only DLL, and copying it onto XP doesn't mean it'll work on XP. If your logic held true, then I'd only need to get a Ferrari keyring to convert my car into one. Bottom line - you can't do this with dwmapi, find another way and stop bumping posts.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Viswa Teja wrote: works fine on vista but my target is on windows xp. I have copyed all the dll's that are reqired
This will not work. You cannot copy those .DLL's from a Vista system and expect them to work on XP. The rendering system work quite a bit differently.
As for the error that you're getting, what you didn't take into account is that the .DLL's you copied are depending on other .DLL's themselves which you haven't copied and that cannot be loaded because of other problems, not the least of which is you're trying to run Vista .DLL's on an XP system.
|
|
|
|
|
Hello to all, now I expose my problem:
I'm developing a program with Visual C# express to calculate the ratio of my radio-controlled model!
How do I enter the following input data:
Number of teeth of spur gear (int), internal ratio (float), and ratio that you want to get (float).
I need as output the number of teeth of the pinion to use. The pinion is obtained with the following formula:
Pinion = (Spur Gear * Ratio) / Internal Ratio
My problem is that I don' t know how to operate the data conversions, because obviously I can' t write:
Int SpurGear = textbox1.Text;
Float Ratio = textbox2.Text;
Float InternalRatio= textbox3.Text;
Float Pinion = (SpurGear * Ratio) / InternalRatio;
label1.text= Pinion;
Etc Etc
Someone can help me?
|
|
|
|
|
Try:
Int SpurGear = int.Parse(textbox1.Text);
Float Ratio = Float.Parse(textbox2.Text);
Float InternalRatio= Float.Parse(textbox3.Text);
Float Pinion = ((Float) SpurGear * Ratio) / InternalRatio;
label1.text= Pinion.ToString();
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Ok thank you very much, now I try it!
|
|
|
|
|
Most of the value types have Parse method for data conversion. Don't forget to have a look at TryParse methods too
|
|
|
|
|
Hi,
a TextBox contains text, so Text returns a string, not a number.
converting strings to some numeric type is called parsing, use the Parse or TryParse method of the target type, e.g. double.TryParse(...) , see documentation.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hello there I am hoping that someone might be able to help me optimize my code for an XNA Program I have made, basically I have made my own custom interface in XNA, now my interface works pretty similar to the ways that windows does, however if you nest too many controls inside each other, then the game really starts to run at a slow rate (fps wise), as it obviously the draw method for the controls are taking too long.
I have tried doing a background draw (using an event via BeginInvoke and EndInvoke), but I get lots of flashing and sometimes it even crashes, as it tries to access the Sprite Batch sometimes when it is still is use
Is there another way to optimize my code that will allow me to get my performance back again??
Here is a sample of the draw code for a container object:
if (m_pTexture != null)
{
graphicsManager.Begin();
if (bSetupClientArea)
graphicsManager.SetupClientRect(TranslatedArea);
if (Image_States == 0 || Image_States == 1)
graphicsManager.Draw(m_pTexture, TranslatedArea, new Color(255, 255, 255, (byte)Alpha));
else
{
int nSubHeight = m_pTexture.Height / Image_States;
Rectangle src = new Rectangle(0, (int)Current_State * nSubHeight, m_pTexture.Width, nSubHeight);
graphicsManager.Draw(m_pTexture, TranslatedArea, src, new Color(255, 255, 255, (byte)Alpha));
}
graphicsManager.End();
DrawBorder(graphicsManager);
}
for (int i = 0; i < m_pComponents.Count; ++i)
{
Component component = m_pComponents[i];
if (component.Visible)
component.Draw(gameTime, graphicsManager, true);
}
As you can see each container has its own Rectangular Area, and it will basically use the graphics manager (which contains the sprite batch object for my XNA Program) to setup it's clip area and draw all of the contents to it, of course using this method means every container has to use begin and end from the graphics manager, to make sure that the objects are drawn correctly
Does calling the SpriteBatch.Begin and End function numerous times cause it to slow down considerably??
Or do you think something else is causing it to slow down??
|
|
|
|
|
jdneul wrote: Does calling the SpriteBatch.Begin and End function numerous times cause it to slow down considerably?
Yes, don't do that. SpriteBatch is a batch for a reason, graphics calls and especially context changes are slow, so it tries to accumulate as many as possible to do many of them at once.
Sometimes it may be required to restart your batch, but I've found that can get quite slow if you do it often.
|
|
|
|
|
i am using the GraphicsDevice.ScissorRectangle to clip all controls, is there another way (code wise) to do this that does not require havin a call to the spritbatch Begin and End just to make sure controls are drawn correctly??
|
|
|
|
|
So you have to clip every control to an other rectangle?
|
|
|
|
|
i can get away with normal controls, because they use textures, you can easily alter the destination and the src to affect the overall look of the interface, but the label controls have strings which are drawn to them and i don't know no easy way to manipulate the DrawSting so that it only draws the correct part of the string depending on it's location in the parent
|
|
|
|
|
Oh drawstring.. It's kinda evil really
I just use my own bitmap fonts, draw them as sprites, like in the old days of XNA 1 - it's just so much more flexible
If you really want to/have to use DrawString, then, I'm sorry but I don't know any clean workarounds
Also, there are usually very few (in any) replies here to XNA questions, it might be better to ask on Ziggyware or something like that
|
|
|
|
|
yeah i was thinking of doing that, thanks for your help again lol, (i presume you mean by using System.Drawing??)
if not can I have some sample code please.
|
|
|
|
|
Hm no, why would you mix XNA with System.Drawing?
I mean you'd have a big texture with all your glyphs on it, and you'd map chars to coordinates on that texture, and keep a list of widths (if it's a variable width font) to update the X coordinate on the screen with
Just use a SpriteBatch for that, it'll be fast because it's all the same texture
|
|
|
|
|
Hi,
In my application i have to print receipt using Dot Matrix Printer(EPSION LQ-300+II). My receipt have preprinted format, in this format i have to send datas using C# code.
My papers size is:Height:10 Inch and Width 9.5 inch. The paper is regular paper.
The problem is in first page datas are printed in required location but in next page it is printed in other location. So, How to set paper size in Crystal Report using C# application for this case: I have set like this:
Reports.frmCrViewer.PaperSize = PaperSize.Paper10x14;
Reports.frmCrViewer.PaperOrientiation = PaperOrientation.DefaultPaperOrientation;
this syntax is correct but the paper size Paper10*14 didn't matched my requirement. So, what should i have to do to print in paper having size 10*9.5 inch.
Please Help Me
|
|
|
|
|
I have a StreamWriter used to create log files and it works fine the first time but if I try to use it again writes fail because the file is not open to write to.
This is called to create a new log file:
FileStream fs = new FileStream(timestr, FileMode.CreateNew);
ScriptData.LogFile = new StreamWriter(fs);
ScriptData.LogFile.WriteLine("Logile created {0:yyyy'-'MM'-'dd'T'HHmmss}.log", DateTime.Now);
This is called to close a file:
ScriptData.LogFile.WriteLine("Script {0} completed.", ScriptData.LogName);
ScriptData.LogFile.Close();
ScriptData.LogFile.Dispose();
ScriptData persists outside the scope of these calls.
Any ideas? All I want to do is be able to write ASCII text to log files.
Thanks.
|
|
|
|
|
Where and how do you destroy the filestream object fs?
The problem is, if you close the underlying filestram, you also close the file.
Greetings
Covean
|
|
|
|
|
The StreamWriter is a member of Scriptdata which is persistent.
|
|
|
|
|
Take a look at your code!
<pre>FileStream fs = new FileStream(timestr, FileMode.CreateNew);
ScriptData.LogFile = new StreamWriter(fs);</pre>
Now if you close fs then your StreamWriter can be a static item from hell, its closed cause you closed the underlying filestream!
StreamWriter is just a class to have a simpler way to transfer data from and to a file.
The FileStream itself "represents" the file!
Greetings
Covean
|
|
|
|
|
Elaine - rather than rolling your own logging solution, you should really look into using something like log4net[^]. We use it all the time now.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete,
that looks good but I'm not sure it would do what I need which is basically to capture the input from a serial port, write it to a file and occasionally insert comments along the way.
Log4net seems to be about logging for the application whereas I am logging the embedded target being controlled.
|
|
|
|
|