|
i do know console programming in c++ you can go to www.planetsourcecode.com and serch Gregory W Bryant under C++ to see my programs but i dont know really any c# and i created the first form as a login the second displays a buddy list now on the second one i have a log out button that i want to close the second form and open the original first form not a new object i have everything done but reopening the first form
|
|
|
|
|
The big tragedy of winforms and designers is that so many people create forms before they learn a little coding, then they get stuck down the line. I would advocate learning console stuff first.
Having said that, if you want to hide form1 while form2 is visible, your best bet is to turn them both into controls and switch which one is visible on a single form.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi friends ..
I have one doubt regarding one 3rd party DLL.I want to generate new DLL.
My logic is
1. import 3rd party DLL
2. new dll = 3rd party dll
3.create new dll
is my way is correct?please explain me!!
*****THANKS N ADVANCE****
Mathen.K
(I WILL TRY MY LEVEL BEST )
|
|
|
|
|
If you only want to use a third party DLL you may simply add reference of DLL in your project and create an object of the class.
If you want to inherit the existing DLL and want to extend functionality of existing class or control, by creating your own custom class library. Use following steps-
1) Start a project of type class library .
2) Add reference of existing DLL file.
3) Inherit the existing class, such as –
public class Class1:ExistingDll.ExistingClass
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
}
After this you may extend functionalities of existing class.
I hope this helps.
-Dave.
Dave Traister,
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
Browse for a file and open the file.
It browses fine; but when i open the folders am unable to see the contends.My basic idea is to browse for a file and select the file inside the selected folder.
My code is
private void btnBrowse_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialogObj = new FolderBrowserDialog();
dialogObj.RootFolder = Environment.SpecialFolder.MyComputer;
if (dialogObj.ShowDialog() == DialogResult.OK) ;
{
OpenFile();
MessageBox.Show("Hello Jane");
}
}
public void OpenFile()
{
OpenFileDialog obj = new OpenFileDialog();
obj.OpenFile();
}
}
}
Am not sure where am going wrong or what has to be done.
Thanking You
|
|
|
|
|
I recommend you give this up and buy a basic book on C#, so you can start at the beginning. You're obvioulsy guessing what to do here.
obj.ShowDialog will show the open file dialog. Then you check the DialogResult to see if the user clicked OK, and then you have a file selected. Even then, obj.OpenFile is not magically going to open the file in your program. You have a ways to go, take a step back and learn some basics.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Just wondering, if you do a Switch stateemtn like this.
Switch var1
case "1":
DoStuff()
case "2":
DoStuff()
case "3":
DoDifferentStuff()
is it possible to group the DoStuff cases, with some sort of OR statement like...
Switch var1
case "1" || "2":
DoStuff()
case "3":
DoDifferentStuff()
|
|
|
|
|
case "2":
case "3":
Dostuff();
break;
Note, you cannot do this:
case "2":
DoCase2Stuff();
case "3":
Docase2and3stuff();
break;
Because C# switch statements are dumbed down on the assumption that the user is stupid.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Because C# switch statements are dumbed down on the assumption that the user is stupid.
Which is true, usually.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Christian Graus wrote: assumption that the user is stupid
No, that some users are much smarter than others, creating too wide a gap in developer abilities; and as they couldn't make the stupid ones smarter, their only recourse was to handicap the smart ones, thereby leveling the playing field.
|
|
|
|
|
I would like to display read-only information on a tab page by simply drawing it using GDI (TextRenderer.DrawText). The problem I'm having is that the text is not persisted by the tabPage surface itself. If I select a different tab then switch back the text is lost with the redwaw. If I use Label controls the control handles persisting the text. What do I need to do to be able to draw on a tab page and have the text stay there until I'm ready to change it? Labels aren't going to cut it.
-Roger
|
|
|
|
|
Well, if it doesn't persist, sounds like you're using CreateGraphics instead of a paint event, just like the fellow below.
You really need to post code if you want us to help you.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
The previous reply is correct, you will need to use paint event of TabPage.
Drawing a line of text should be as simple as using following code in paint event-
Graphics g = e.Graphics ;
g.DrawString("Some text",MyFontObj,Brushes.Black,10,10);
I hope this helps.
-Dave.
Dave Traister,
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
I've been programming C# for a couple years now in the academic setting, but I've been curious about the recommended place to put Main() in a Windows Forms application. I know of two ways to do it. One is to simply place Main() in the same class as the primary form, as below:
using System;
using System.Windows.Forms;
namespace TestCode
{
public class MyForm : Form
{
public static void Main(String[] args)
{
Application.Run(new MyForm());
}
}
}
The other method is to create a separate class and put Main() in there, as below:
using System;
using System.Windows.Forms;
namespace TestCode
{
public class MyForm : Form
{
}
public class MyApp
{
public static void Main(String[] args)
{
Application.Run(new MyForm());
}
}
}
I've found that most people use the first method, but the second method seems better to me because it keeps the application logic and whatnot out of the GUI code. Are either of these two the "better" option? Or is it merely a matter of preference?
Thanks.
|
|
|
|
|
I've never given it a second thought.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Usually just east of New Hampshire.
|
|
|
|
|
Hi! I had created a picture box and a button. When I click on the button one circle and one rectangle will be drawn on the picture box. I would like to implement drag and drop effect on the picture box so that both circle and rectangle can be move freely in picture box area. Does anyone know how to implement it? Because I don't have any idea where to start. Thanks in advance for the help.
Here is my code on drawing that 2 shapes in picture box:-
using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace test_drag
{
public partial class Window1
{
private Graphics g;
private System.Drawing.Pen pen1;
Bitmap bitmap;
public Window1()
{
this.InitializeComponent();
bitmap = new Bitmap(pictureBox.Width,pictureBox.Height);
g = Graphics.FromImage(bitmap);
// Insert code required on object creation below this point.
}
private void create_Click(object sender, RoutedEventArgs e)
{
pen1 = new System.Drawing.Pen(System.Drawing.Color.Blue, 1);
g.DrawRectangle(pen1, 10, 10, 50, 50);
g.DrawEllipse(pen1, 10, 80, 30, 30);
pen1.Dispose();
using (Graphics h = pictureBox.CreateGraphics())
{
h.DrawImageUnscaled(bitmap, 0, 0, pictureBox.Width, pictureBox.Height);
h.Dispose();
}
}
}
}
|
|
|
|
|
yuenli wrote: using (Graphics h = pictureBox.CreateGraphics())
This is a disaster, never use it. Open your app, then open calculator. Draw some stuff in your app. Now drag calculator across your app and out again. See how your drawings have disappeared ? That's because you used creategraphics.
The paint event is where you need to do all drawing. You force a paint event by calling Invalidate().
What do you mean by drag and drop ? Whatever you mean, you need to keep your shapes in an array, and iterate over that array to draw them in your paint event. Then you can make one shape your selected shape, and change it's position while forcing a paint, so the shape moves when it's redrawn.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Christian,
Thanks for the reply. Actually I am a newbie. May I know what do you mean by keep shapes in array and draw them in paint event. Do you mean that each time I change a shape location I have to recall the paint event? And How to I make selected shape by allowing user to select it? I wish to do something like Paint application where you can select the drawn shape and move it to new location inside the drawing area. Thanks.
|
|
|
|
|
It sounds to me like you need to start with something more basic.
Your shapes should be represented by class instances. Ideally they'd know how to draw themselves, just taking a graphics object. Yes, calling Invalidate to force a paint event is THE way to make a windows app redraw itself. Then you have your list of shapes and you iterate over them, getting them all to draw themselves. You'd also store the co-ordinates of each one and you'd iterate over them all when the mouse goes down, to work out which one is under the mouse, and mark it as selected.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
That means I only need to play with On mouse up and on mouse down event and everytime call the paint function to reload whole thing. Am I right?
|
|
|
|
|
No, if you're moving the object, you need to repaint in onmousemove, and also move your object by however far the mouse has moved first.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Does that mean in on mouse move function i need to get the x y position of selected shape and repaint the whole drawing? This step is also apply in on mouse up right? Thanks.
|
|
|
|
|
The drawing all happens in OnPaint. What you need to do in the mouse move, is move your shape if the mouse is down, so that it moves the amount that the mouse has moved. Then call invalidate() to force a repaint, which draws the shape in it's new position.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi!
I try to over write the onPaint event handler but it seem that got error. This is because I embeded picture box to windows host form in xaml files. Can anyone help me to solve this problem? Really thanks for the help.
XAML code:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns ="http://schemas.microsoft.com/expression/blend/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="test_drag.Window1"
x:Name="Window"
Title="Window1"
Width="516"
Height="694"
>
<Grid x:Name="LayoutRoot">
<WindowsFormsHost x:Name="host1" Background="#FFE1E0E0" AllowDrop="True" Margin="0,0,92,0" VerticalAlignment="Top" Height="312" >
<wf:PictureBox x:Name="pictureBox" Width="300" Height="300" Paint="pictureBox_Paint" />
</WindowsFormsHost>
</Grid>
</Window>
C# coding:
using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Documents;
using System.Windows.Markup;
namespace test_drag
{
public partial class Window1
{
Font font;
public Window1()
{
this.InitializeComponent();
font = new Font("Arial", 10);
// Insert code required on object creation below this point.
}
private void pictureBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawString("This text is render", font, System.Drawing.Brushes.Red, 0, 0);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawString("this overrride", font, System.Drawing.Brushes.Blue, 5, 5);
}
}
}
|
|
|
|