|
Which books are good for this kind of coding?
|
|
|
|
|
Sorry, I seldom recommend books as their value very much depends on someones background and prior knowledge;
I tend to like the Microsoft Step by Step series; e.g. "MicroSoft Visual C#.NET Step by Step" by John Sharp and Jon Jagger.
What I do recommend is described here[^].
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Ok, but can u give me an example plz Can't get my to work :S
|
|
|
|
|
You should be more concerned with learning programming than with getting a program to work, simply because the other way around is an unnatural order to proceed in, and thus a very difficult way to go about it. If you don't want to learn programming there are probably plenty of free programs on the market that do all you want and more.
That said, this is all there is to showing a dialog and reading the contents of a text file:
string readTextFile()
{
var dlg = new OpenFileDialog();
if (dlg.ShowDialog() != DialogResult.OK) return null;
using (StreamReader sr = File.OpenRead(dlg.FileName))
return sr.ReadToEnd();
}
This is a simplistic implementation. Normally you'd want to add the dialog as a component to your form, just because that will let you set filters or other properties using the designer rather than coding, and use that dialog in the method. If you were to support huge files you also might not want to read the entire file since the user won't be able to view more than a tiny bit of it at a time and it's kind of wasteful to keep it all in memory (and may not be possible to keep it all in the textbox control at once). But given that you couldn't figure out how to read a file even with links to articles about the subject I think you should just forget about large files.
Hopefully you can figure out how to assign the Text property on your own.
|
|
|
|
|
hi
How to print (and preview) any document - but not with CrystalReport
(working on VS2008 - C#)
ex. i have 6 val's in my C# program that i want to print (and preview)
how i can do it ?
thank's in advance
|
|
|
|
|
Printing is a rather complex matter. Printing a Form is based on the Paint handler and the PrintDocument class. My Sokoban article offers a simple example.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
your project not open on my VS2008
is there any sample code for this ?
|
|
|
|
|
It probably is a VS2005 project, which VS2008 can convert.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
E_Gold wrote: How to print (and preview) any document
And while on the subject of magic: How to do anything and everything automatically?
Hint: Any document implies a system that can intelligently reverse-engineer any format presented to it, past, present or future, as well as one that can break encryption that is considered unbreakable. In short, you are asking for nothing less than magic.
|
|
|
|
|
it's 00:30 and I lost my mind in a few beers, came home and would do some coding before I hit the showers, but now I forgot an important part...
I remember how to add values and text to a combobox via a datasource, but can any remember how to add both text and value in a static way?
ie.
Combobox1.Items.Add(new ????("text","value"));
yes, yes I know, don't code drunk.
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:59am.
|
|
|
|
|
nah can't really use that solution, then I wouldnt be able to use SelectedValue to get the current selected value and would have to rewrite too much code as I then couldnt load the combobox values elsewhere.
but thanks for the effort.
|
|
|
|
|
Why don't you create a static datatable with your static data??
static DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
dt.Columns.Add("MyTextToShow");
dt.Columns.Add("MyValueToShow");
dt.Rows.Add("OneText", 1);
dt.Rows.Add("TwoText", 2);
dt.Rows.Add("ThreeText", 3);
comboBox1.DataSource = dt;
comboBox1.ValueMember = "MyValueToShow";
comboBox1.DisplayMember = "MyTextToShow";
}
regards... and don't code drunk! is hateful haha
|
|
|
|
|
hi there
i am writing a program for video conference over internet i was looking for a sample for capturing a image from webcam i found that there is two way for doing this first is using WIA and second is using API i found a sample that use API (avicap32.dll) it work fine now i want to add another camera or webcam and the aouther is not accessible .i reviewed codes several times but i cant understand that. it is really complicated for me and as i cant understand the code i cant extend it for capturing image or video from any other devices synchronouslly here is the code and i would be really appriciated if you explan about the codes :
the class for capturing and sending image:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WebCam_Capture
{
[System.Drawing.ToolboxBitmap(typeof(WebCamCapture), "CAMERA.ICO")]
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(System.ComponentModel.Design.IDesigner))]
public class WebCamCapture : System.Windows.Forms.UserControl
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Timer timer1;
private int m_TimeToCapture_milliseconds = 100;
private int m_Width = 320;
private int m_Height = 240;
private int mCapHwnd;
private ulong m_FrameNumber = 0;
private WebCam_Capture.WebcamEventArgs x = new WebCam_Capture.WebcamEventArgs();
private IDataObject tempObj;
private System.Drawing.Image tempImg;
private bool bStopped = true;
public delegate void WebCamEventHandler (object source, WebCam_Capture.WebcamEventArgs e);
public event WebCamEventHandler ImageCaptured;
#region API Declarations
[DllImport("user32", EntryPoint="SendMessage")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
[DllImport("avicap32.dll", EntryPoint="capCreateCaptureWindowA")]
public static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID);
[DllImport("user32", EntryPoint="OpenClipboard")]
public static extern int OpenClipboard(int hWnd);
[DllImport("user32", EntryPoint="EmptyClipboard")]
public static extern int EmptyClipboard();
[DllImport("user32", EntryPoint="CloseClipboard")]
public static extern int CloseClipboard();
[DllImport("avicap32.dll", EntryPoint = "capgetdeviiceproperties")]
public static extern int capgetdeviiceproperties(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID);
#endregion
#region API Constants
public const int WM_USER = 1024;
public const int WM_CAP_CONNECT = 1034;
public const int WM_CAP_DISCONNECT = 1035;
public const int WM_CAP_GET_FRAME = 1084;
public const int WM_CAP_COPY = 1054;
public const int WM_CAP_START = WM_USER;
public const int WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41;
public const int WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42;
public const int WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43;
public const int WM_CAP_GET_VIDEOFORMAT = WM_CAP_START + 44;
public const int WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45;
public const int WM_CAP_DLG_VIDEOCOMPRESSION = WM_CAP_START + 46;
public const int WM_CAP_SET_PREVIEW = WM_CAP_START + 50;
#endregion
#region NOTES
#endregion
public WebCamCapture()
{
InitializeComponent();
}
~WebCamCapture()
{
this.Stop();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
this.Name = "WebCamCapture";
this.Size = new System.Drawing.Size(342, 252);
}
#endregion
#region Control Properties
public int TimeToCapture_milliseconds
{
get
{ return m_TimeToCapture_milliseconds; }
set
{ m_TimeToCapture_milliseconds = value; }
}
public int CaptureHeight
{
get
{ return m_Height; }
set
{ m_Height = value; }
}
public int CaptureWidth
{
get
{ return m_Width; }
set
{ m_Width = value; }
}
public ulong FrameNumber
{
get
{ return m_FrameNumber; }
set
{ m_FrameNumber = value; }
}
#endregion
#region Start and Stop Capture Functions
public void Start(ulong FrameNum)
{
try
{
this.Stop();
mCapHwnd = capCreateCaptureWindowA("WebCap", 0, 0, 0, m_Width, m_Height, this.Handle.ToInt32(), 0);
Application.DoEvents();
SendMessage(mCapHwnd, WM_CAP_CONNECT, 0, 0);
SendMessage(mCapHwnd, WM_CAP_SET_PREVIEW, 0, 0);
m_FrameNumber = FrameNum;
this.timer1.Interval = m_TimeToCapture_milliseconds;
bStopped = false;
this.timer1.Start();
}
catch (Exception excep)
{
MessageBox.Show("An error ocurred while starting the video capture. Check that your webcamera is connected properly and turned on.\r\n\n" + excep.Message);
this.Stop();
}
}
public void Stop()
{
try
{
bStopped = true;
this.timer1.Stop();
Application.DoEvents();
SendMessage(mCapHwnd, WM_CAP_DISCONNECT, 0, 0);
}
catch (Exception excep)
{
}
}
#endregion
#region Video Capture Code
private void timer1_Tick(object sender, System.EventArgs e)
{
try
{
this.timer1.Stop();
SendMessage(mCapHwnd, WM_CAP_GET_FRAME, 0, 0);
SendMessage(mCapHwnd, WM_CAP_COPY, 0, 0);
if (ImageCaptured != null)
{
tempObj = Clipboard.GetDataObject();
tempImg = (System.Drawing.Bitmap) tempObj.GetData(System.Windows.Forms.DataFormats.Bitmap);
x.WebCamImage = tempImg.GetThumbnailImage(m_Width, m_Height, null, System.IntPtr.Zero);
this.ImageCaptured(this, x);
}
Application.DoEvents();
if (! bStopped)
this.timer1.Start();
}
catch (Exception excep)
{
MessageBox.Show("An error ocurred while capturing the video image. The video capture will now be terminated.\r\n\n" + excep.Message);
this.Stop();
}
}
#endregion
}
}
thanks in advance
modified on Saturday, November 21, 2009 1:52 PM
|
|
|
|
|
Firstly you should put your code between <pre></pre> tags so it retains its formatting. The above code is very difficult to read, please edit the entry.
Secondly if you do not understand the code then you really should not be trying to use it. The most important aspect of any application is that you understand the code you are using. This forum does not have the space (and contributors do not have the time) to provide tutorials in this fashion. If this code came from an internet article then you should spend time studying the article until you understand it.
|
|
|
|
|
Whats the betting he just puts <pre>...</pre>tags around the existing unformated code?
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
"Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"
|
|
|
|
|
Richard MacCutchan wrote: Secondly if you do not understand the code then you really should not be trying to use it.
I don't think this is the right way to look at it. Just because you don't understand the code doesn't mean you shouldn't try to use it in order to gain said understanding.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I think the rest of my comment tried to put this in context. I was trying to make the point that getting someone else to modify the code to do what he wants will not enhance his understanding of it.
|
|
|
|
|
at first excuse me because of confusing you i corrected the code and here is the site that i downloaded the file:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1339&lngWId=10[^]
|
|
|
|
|
Richard MacCutchan wrote: if you do not understand the code then you really should not be trying to use it
That depends on what the code is! Most of us use code all the time that we don't understand - in the .net framework. And it truly would be a waste of time to study every implementation detail (most of which are undocumented!) of the primitive types before permitting oneself to use them. I do not know the exact representation of System.Decimal nor what bit-level manipulation it performs to carry out a multiplication, but it would be ridiculous to claim I shouldn't use decimals for that reason.
Also, even code that was not written with the intent of becoming a library (though most code should be written that way imo!) can still be of good quality and of great utility. Trying to use it is sometimes the most effective way to learn about it, whether it's good or bad code, especially if one does not have access to documentation.
|
|
|
|
|
This reply was aimed at the OP, who has downloaded some code from the internet that they admit to not understanding, and then wants a major change made to implement a feature that they probably understand less. It was not aimed at people who provide the answers on these forums. And I know that we all use unfamiliar code to learn new things, but we also spend a lot of time answering questions like this from people who have not taken the time to learn some of the basics.
|
|
|
|
|
OK. I think we've both made some valid points. It's not necessary to interpret any additional perspectives as implying "you're wrong" and it's not really a competition.
|
|
|
|
|
dojohansen wrote: It's not necessary to interpret any additional perspectives as implying "you're wrong"
I was not for a moment implying this, so I hope you did not read it that way. I do accept the points you made, I was merely trying to clarify my earlier message which may not have been as clear as I thought it was.
|
|
|
|
|
And by the way,
Richard MacCutchan wrote: but we also spend a lot of time answering questions like this from people who have not taken the time to learn some of the basics.
If we do, we do so only by choice. (Reading them is at least partly another matter.)
|
|
|
|
|
First, you have to tell us where you got the code so we have a context in which to help yopu.
Second, you need to properly format the code you posted into a properly tagged PRE block.
Third, you need to use punctuation in your description so we can read it.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|