|
I have a scrollbar with properties set below:
min: 0
max: 100
LargeChange: 10
SmallChange: 1
Now at run-time, I try to scroll the scrollbar to its max position using mouse, but it is impossible! I can only scroll it up to:
Max-LargeChange+1
here it is 91
The strange thing is that I can programatically set the scrollbar's value to 100.
What the hell should I do with this damn control?
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Hi,
I have a simple application. I want to draw two concentric circles and a bunch of random dots between the circles that are refreshed periodically. I could code this app in either GDI+ or DirectDraw. My question is will any one of these give me higher efficiency (faster processing)? As I understand GDI+ does all its graphics processing in memory i.e. is s/w based does not take advantage of hardware acceleration.
I am completely new to direct draw but it appears in my app I would be first drawing onto the back buffer surface and then while rendering flip the front buffer with the back buffer. The Surface object which ddraw provides is a memory object so how is ddraw taking any advantage of graphics hardware?
Also could anyone explani to me the SetDisplayMode method of ddraw?
sid
|
|
|
|
|
direct draw is faster, that's what it's for. The question is, do you need to be that fast ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
To (hopefully) clarify further: The technology formerly known as DirectDraw ended with DirectX 7. DirectX 8 pulled the DirectDraw functionality into the Direct3D interface, and in DirectX9 a managed wrapper for this interface was introduced. So if you want to use C# you should use Managed DirectX9. When you create the D3D surface you specify whether you want it created in system memory or on the graphics card. Obviously if you want acceleration you create it "directly" (get it?) on the card. What specifically about SetDisplayMode don't you understand?
Michael Blome [MS]
|
|
|
|
|
HI,
I am using DX9 and I think DDraw does not end with DX7, its there in DX9 also. ANyway I created two projects - one in GDI+ another in DDraw9 and I find ddraw is much much slower than GDI+ - obviously it seems I am making a mistake somewhere but where? Please see the DisplayFrame method in my DDraw code.
Regarding SetDisplayMode:
is the fourth parameter the graphics card refresh rate you want to set and its specified in Hz?
I have no idea what the fifth parameter means.
This is my GDI+ code (I would be happy to send you the entire project for GDI+ and Ddraw if you want) - the OnPaint method is of interest:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace enigma1
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics dc = e.Graphics;
Double area = Math.PI*(m_RadiusOuter*m_RadiusOuter
- m_RadiusInner*m_RadiusInner);
Int32 n = (Int32) ((m_DotDensity / (128*128)) * area);
this.WindowState = FormWindowState.Maximized;
this.BackColor = Color.White;
Int32 centery = this.Bottom / 2;
Int32 centerx = this.Right / 2;
dc.DrawEllipse(m_PenInner, centerx-m_RadiusInner,
centery-m_RadiusInner, 2*m_RadiusInner, 2*m_RadiusInner);
dc.DrawEllipse(m_PenOuter, centerx-m_RadiusOuter,
centery-m_RadiusOuter, 2*m_RadiusOuter, 2*m_RadiusOuter);
// draw n random dots
for(Int32 ctr = 0; ctr < n; ctr++)
{
Double theta = (Double) m_Rnd.Next()/Int32.MaxValue * 2*Math.PI;
Double r = m_Rnd.Next(m_RadiusInner+1, m_RadiusOuter-1);
Double cx = centerx + r*Math.Cos(theta);
Double cy = centery - r*Math.Sin(theta);
dc.DrawEllipse(m_DotPen, (float) cx - m_DotSize,
(float) cy - m_DotSize,
(float) 2*m_DotSize, (float) 2*m_DotSize);
dc.FillEllipse(m_DotBrush, (float) cx-m_DotSize,
(float) cy - m_DotSize,
(float) 2*m_DotSize, (float) 2*m_DotSize);
}
// pause for m_t1 ticks
System.Threading.Thread.Sleep(100);
// for(Int32 ctr = 0; ctr < 0xafffff; ctr++);
// blank the screen for m_t2 ticks
this.BackColor = Color.White;
System.Threading.Thread.Sleep(100);
// for(Int32 ctr = 0; ctr < 0xafffff; ctr++);
this.Invalidate(); // redraw again
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(692, 466);
this.Name = "Form1";
this.Text = "Form1";
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Form1 f1 = new Form1();
f1.GetInputs();
// following displays the screen resolution
// MessageBox.Show(Screen.PrimaryScreen.Bounds.Right.ToString() + " x " + Screen.PrimaryScreen.Bounds.Bottom.ToString());
//
Application.Run(f1);
}
public void GetInputs()
{
m_DotSize = 2;
m_t1 = 10;
m_t2 = 10;
m_PenInner = new Pen(Color.Black);
m_PenOuter = new Pen(Color.Blue);
m_RadiusInner = 64;
m_RadiusOuter = 128;
m_DotDensity = 20;
m_Rnd = new Random();
m_DotPen = new Pen(Color.Black);
m_DotBrush = new SolidBrush(Color.Black);
}
private Int32 m_DotSize;
private Int32 m_t1;
private Int32 m_t2;
private Pen m_PenInner;
private Pen m_PenOuter;
private Int32 m_RadiusInner;
private Int32 m_RadiusOuter;
private Double m_DotDensity;
private Random m_Rnd;
private Pen m_DotPen;
private Brush m_DotBrush;
///
/// Processes key up events.
///
private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
// If the user presses the Escape key, the app needs to exit.
if (Keys.Escape == e.KeyCode)
Close();
}
}
}
THIS IS MY DDRAW CODE (the DisplayFrame method is of interest):
//-----------------------------------------------------------------------------
// File: AnimatePalette.cs
//
// Desc: AnimatePalette demonstrates DirectDraw palette animation when in full-screen
// on a palettized surface.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectDraw;
namespace AnimatePalette
{
public class AnimatePalette : System.Windows.Forms.Form
{
// Declare the class scope variables here.
public void GetInputs()
{
m_DotSize = 2;
m_t1 = 10;
m_t2 = 10;
m_PenInner = new Pen(Color.Black);
m_PenOuter = new Pen(Color.Blue);
m_RadiusInner = 64;
m_RadiusOuter = 128;
m_DotDensity = 20;
m_Rnd = new Random();
m_DotPen = new Pen(Color.Black);
m_DotBrush = new SolidBrush(Color.Black);
}
private Int32 m_DotSize;
private Int32 m_t1;
private Int32 m_t2;
private Pen m_PenInner;
private Pen m_PenOuter;
private Int32 m_RadiusInner;
private Int32 m_RadiusOuter;
private Double m_DotDensity;
private Random m_Rnd;
private Pen m_DotPen;
private Brush m_DotBrush;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
const int indexBlack = 144; // Index of the palette entry that contains black.
const int indexWhite = 0; // Index of the palette entry that contains white.
const int screenWidth = 640; // Screen width.
const int screenHeight = 480; // Screen height.
Device displayDevice = null; // The Direct Draw Device.
Surface front = null; // The front surface.
Surface back = null; // The back surface.
Palette pal = null; // The palette the front surface will use.
int tickLast = 0; // Holds the value of the last call to GetTick.
bool restoreNeeded = false;// Flag to determine the app needs to restore the surfaces.
PaletteEntry[] pe = new PaletteEntry[256]; // Palette entry array.
///
/// Entry point for the application.
///
public static void Main()
{
AnimatePalette app = new AnimatePalette();
Application.Exit();
}
///
/// Constructor for the main class.
///
public AnimatePalette()
{
//
// Required for Windows Form Designer support.
//
InitializeComponent();
// Make sure to use the arrow cursor.
Cursor = Cursors.Arrow;
// Create a new DrawDevice.
InitializeDirectDraw();
this.GetInputs();
// Keep looping until app quits.
while (Created)
{
ProcessNextFrame(); // Process and draw the next frame.
Application.DoEvents(); // Make sure the app has time to process messages.
}
}
///
/// Restore all the surfaces, and redraw the sprite surfaces.
///
void RestoreSurfaces()
{
/*
SurfaceDescription description = new SurfaceDescription();
*/
displayDevice.RestoreAllSurfaces();
// We need to release and re-load, and set the palette again to
// redraw the bitmap on the surface. Otherwise, GDI will not
// draw the bitmap on the surface with the correct palette.
/*
pal.Dispose();
pal = null;
front.Palette = pal;
*/
// Release and re-load the sprite bitmap.
/*
surfaceLogo.Dispose();
surfaceLogo = new Surface(bitmapFileName, description, displayDevice);
ColorKey ck = new ColorKey();
surfaceLogo.SetColorKey(ColorKeyFlags.SourceDraw, ck);
*/
return;
}
///
/// Move the sprites, blt them to the back buffer, then
/// flips the back buffer to the primary buffer
///
private void ProcessNextFrame()
{
// Figure how much time has passed since the last time.
int CurrTick = Environment.TickCount;
int TickDiff = CurrTick - tickLast;
// Don't update if no time has passed.
if (0 == TickDiff)
return;
tickLast = CurrTick;
//Draw the sprites and text to the screen.
DisplayFrame();
}
private void DisplayFrame()
{
if (null == front)
return;
if (false == displayDevice.TestCooperativeLevel())
{
restoreNeeded = true;
return;
}
if (true == restoreNeeded)
{
restoreNeeded = false;
// The surfaces were lost so restore them .
RestoreSurfaces();
}
// Fill the back buffer with black.
// back.ColorFill(indexBlack);
back.ColorFill(System.Drawing.Color.White);
Double area = Math.PI*(m_RadiusOuter*m_RadiusOuter
- m_RadiusInner*m_RadiusInner);
Int32 n = (Int32) ((m_DotDensity / (128*128)) * area);
Int32 centery = this.Bottom / 2;
Int32 centerx = this.Right / 2;
back.ForeColor = Color.Black;
back.FillStyle = 1;
back.DrawCircle(centerx, centery, m_RadiusInner);
back.DrawCircle(centerx, centery, m_RadiusOuter);
back.FillStyle = 0;
// draw n random dots
for(Int32 ctr = 0; ctr < n; ctr++)
{
Double theta = (Double) m_Rnd.Next()/Int32.MaxValue * 2*Math.PI;
Double r = m_Rnd.Next(m_RadiusInner+1, m_RadiusOuter-1);
Double cx = centerx + r*Math.Cos(theta);
Double cy = centery - r*Math.Sin(theta);
back.DrawCircle((Int32) cx, (Int32) cy, (Int32) m_DotSize);
/*
dc.FillEllipse(m_DotBrush, (float) cx-m_DotSize,
(float) cy - m_DotSize,
(float) 2*m_DotSize, (float) 2*m_DotSize);
*/
}
// We are in fullscreen mode, so perform a flip.
front.Flip(back, FlipFlags.DoNotWait);
// pause for m_t1 ticks
System.Threading.Thread.Sleep(20);
// for(Int32 ctr = 0; ctr < 0xafffff; ctr++);
// blank the screen for m_t2 ticks
back.ColorFill(Color.White);
// We are in fullscreen mode, so perform a flip.
front.Flip(back, FlipFlags.DoNotWait);
System.Threading.Thread.Sleep(20);
}
///
/// Initializes DirectDraw and all the surfaces to be used.
///
private void InitializeDirectDraw()
{
SurfaceDescription description = new SurfaceDescription(); // Describes a surface.
displayDevice = new Device(); // Create a new DirectDrawDevice.
displayDevice.SetCooperativeLevel(this, CooperativeLevelFlags.FullscreenExclusive); // Set the cooperative level.
try
{
displayDevice.SetDisplayMode(screenWidth, screenHeight, 8, 0, false); // Set the display mode width and height, and 8 bit color depth.
}
catch(UnsupportedException)
{
MessageBox.Show("Device doesn't support required mode. Sample will now exit.", "UnsupportedException caught");
Close();
return;
}
description.SurfaceCaps.PrimarySurface = description.SurfaceCaps.Flip = description.SurfaceCaps.Complex = true;
description.BackBufferCount = 1; // Create 1 backbuffer.
front = new Surface(description, displayDevice); // Create the surface using the description above.
SurfaceCaps caps = new SurfaceCaps();
caps.BackBuffer = true; // Caps of the surface.
back = front.GetAttachedSurface(caps); // Get the attached surface that matches the caps, which will be the backbuffer.
front.ColorFill(Color.White);
/*
pal = new Palette(displayDevice, bitmapFileName); // Create a new palette, using the bitmap file.
pe = pal.GetEntries(0, 256); // Store the palette entries.
front.Palette = pal; // The front surface will use this palette.
*/
}
///
/// Clean up any resources being used.
///
protected override void Dispose(bool disposing)
{
if (disposing)
{
displayDevice.RestoreDisplayMode(); // Restore the display mode to what it was.
displayDevice.SetCooperativeLevel(this, CooperativeLevelFlags.Normal); // Set the cooperative level back to windowed.
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// AnimatePalette
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(208, 69);
this.ForeColor = System.Drawing.Color.Black;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.KeyPreview = true;
this.Name = "AnimatePalette";
this.Text = "AnimatePalette";
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.AnimatePalette_KeyUp);
}
#endregion
///
/// Processes key up events.
///
private void AnimatePalette_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
// If the user presses the Escape key, the app needs to exit.
if (Keys.Escape == e.KeyCode)
Close();
}
}
}
|
|
|
|
|
Hi everyone,
Probably a real newbie question. How can I prepend to a file in C#. I have a file and I want to attach a header to it in front. Is there an easy API available to do something like this?
Thanks,
Sincerely,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
As with everything in the .net framework, there is an API. In fact, there are several. And as you might imagine, there's more than one way to solve the problem. Start out with the MSDN library here and the exact algorithm is up to you. There are several useful examples.
|
|
|
|
|
how can i send an image from a pictureBox using a NetworkStream. I need the code, starting from declaring stream then socket and so on.
thnks....
|
|
|
|
|
Get a reference to the Image from PictureBox.Image and call Image.Save(Stream, ImageFormat) using an initialized NetworkStream as the first parameter and whatever ImageFormat you want to save it in. See the documentation in the .NET Framework SDK for more information on the mentioned classes. Reading the SDK is an important part of development. The information above should be more than enough.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
The information above should be more than enough.
Amen. Reading some questions I often think, "Did this person even try to search through MSDN or SDK documentation before asking everyone else?"
|
|
|
|
|
Hi,
I'm developing a Activex with .net C++, i try to add a method that has both external and internal name into this activex, so that I can call this method ourside of this activex. but I can notfind a way to do this job as we do this with classwizard in VC.
So pls help me, if you know how to solve this problem?
thx.
Ray
|
|
|
|
|
First of all, this is the C# forum, not the C++ forum. These are two completely different languages.
If you want to call the method both externally and internally, you should declare the method as public (which any COM method must be anyway). If you're using Managed C++, declaring a public method is not merely enough. You should define a class interface (.NET can automatically generate one for you, but this is not recommended for many reasons), attribute your interface and class with different GuidAttribute s, and several more attributes. You can call this public method internally with no problems.
For more information about exposing .NET Controls as COM components, see http://msdn.microsoft.com/library/en-us/cpguide/html/cpconexposingnetframeworkcomponentstocom.asp[^]. There's also a pretty good article here on CodeProject, but it's in C# (though if you truly understand the .NET Framework and not just a language, translating this should be no problem): http://www.codeproject.com/dotnet/nettocom.asp[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi there
Is it possible to play flash swfs in c# forms?
and also interact with them?
does anyone know how to do this?
Regards
VisionTec
|
|
|
|
|
You can use flash player control using COM Interoperability.
Just customize your toolbox and add that control to current controls from COM tab(flash player should be already installed). And for interacting with swf file you can use FSCommand . For more information refer to FSCommand documentation.
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
here is the solution:
1.right click on toolbox at general tab
2.select add new items
3.one popup window appears to add references
4.select COM tab
5.navigate to shock wave object select that
6.click on ok
7.u will see the flash object on General tab
|
|
|
|
|
Hi there
i an a newbie to c#
how can i change the date to british date format?(dd-mm-yy)
in my applications?
VisionTec
|
|
|
|
|
Here is an example:
MessageBox.Show(DateTime.Now.ToString("dd-MM-yy"));
|
|
|
|
|
A better way is to use an IFormatProvider for the British CultureInfo . For example, String.Format can take an IFormatProvider as the first parameter. This could be the CultureInfo.NumberFormat for the CultureInfo for the English (Britain) culture. By default, such methods uses the Thread.CurrentCulture but as I've mentioned you can override this behavior by passing an IFormatProvider . This is the correct way, instead of assuming and managing custom format specifiers like the previous post mentioned.
For more information about localization and culture-specific formatting, see Developing World-Read Applications[^] in the .NET Framework SDK. With regard to your question, see Formatting Date and Time for a Specific Culture[^] under the previous topic.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Everyone,
I have been looking around the web for info on how to hide/disable the 'Start Button' in WinXP using C#. Have found a few references to doing it using other languages but nothing with C#. A lot of them seem to reference 'Shell_TrayWnd'. Is this possible in C#. Need it to lockdown pc. Have disabled a lot of the functionality I need by editing the System Registry using C# and this would be the final piece of the jigsaw. If there is anyone who knows how to do it in C# or any other way, say through the Registry, I would really appreciate your suggestions,
Regards,
John
|
|
|
|
|
This is not really a programming question if all you want to do is "lock-down" the OS (which, BTW, there is no documented registry hack for disabling the Start menu - it's pretty much required). If you want your program to work as a kiosk, you can implement a full-screen application (search the previous comments since this has been covered more times than necessary) and use system hooks to disable certain key combinations that allow users to bypass your application's handlers.
There are several articles here on CodeProject that deal with hooks and you can find more information about them in the Platform SDK. For one decent article, see Using Hooks from C#[^] or search CodeProject for additional articles.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
thanks for the reply. But I have found the following VB code to do the job. It just hides the Start Button (true/false values passed). It doesnt disable it as you can still press the windows button on the keyboard, but thats not a problem. Is there anyone who knows how to implement this code is C#, or can I place it in the C# project as is an call it someway??
#####################################
'
' Paste this into a Code Mode (BAS)
'
option Explicit
'
private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (byval hWnd1 as Long, byval hWnd2 as Long, byval lpsz1 as string, byval lpsz2 as string) as Long
'
private Declare Function EnableWindow Lib "user32" (byval hwnd as Long, byval fEnable as Long) as Long
public Sub EnableStartMenuButton(byval bEnable as Boolean)
'
' Don't forget to re-enable it !
'
Dim lHwnd as Long
'
lHwnd = FindWindowEx(0&, 0&, "Shell_TrayWnd", vbNullString)
lHwnd = FindWindowEx(lHwnd, 0&, "Button", vbNullString)
Call EnableWindow(lHwnd, bEnable)
'
End Sub
'
#####################################
Thanks Again,
John
|
|
|
|
|
You simply need to P/Invoke these functions, but again I warn you that this is not the correct way to make a kiosk application. If this is your goal, you should check out the Platform SDK in the MSDN Library at http://msdn.microsoft.com/library[^].
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string class1, string class2);
[DllImport("user32.dll")]
private static extern void EnableWindow(IntPtr hWnd, bool enable);
public static void EnableStartButton(bool enable)
{
IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
hWnd = FindWindowEx(hWnd, IntPtr.Zero, "Button", null);
EnableWindow(hWnd, enable);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi there
i have an mdi form which has a few child forms
in the mdi form i have a status bar
how can i add text to the status bar from the child forms?
VisionTec
|
|
|
|
|
You simply need to expose the StatusBar (or better yet, the StatusBar.Text property for a better OO design in reference to encapsulation and protection) on the main form. Your child forms could so something like this, assuming that your main form (ex, MainForm ) had a String property called StatusText :
MainForm form = (MainForm)this.MdiParent;
form.StatusText = "Hello, world!" Honestly, how you provide access to status bar is completely up to your implementation. This is simply a matter of creating a good object-oriented design.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am trying to convert an old MFC GUI which fires off a continuously running C++ program into a C# GUI which will fire off a continuously running C# program. The former used two pipes to pass information back and forth. I cannot seem to find the .Net compliment of pipes in any of the .NET documentation. Any help would be greatly appreciated. Thanks...
|
|
|
|
|