0
C#에서 만든 2 Windows Forms에 문제가 있습니다. 첫 번째 양식 (메뉴)에는 PrintPreviewDialog 객체가 있습니다. 그런 다음 "메뉴"양식은 송신 클래스 "파일"의 사본을 인스턴스화하고 ShopDialog 메소드를 호출합니다.C와 컨텍스트 문제가 있습니다 #
"파일"클래스는 파일을 쓰고 "메뉴"클래스에서 직접 (직접) 메서드를 호출합니다.
내가 가진 문제는 "직접적인"방법이 "메뉴"클래스에 알려져 있지 않다는 것입니다. 대답은 "파일"에서 "메뉴"클래스의 복사본을 정의하는 것이지만 생각하지 않아도됩니다.
사전에 도움을 주셔서 감사합니다.
요한은
namespace CSharp
{
public partial class MainMenu : Form
{
// Fields for printing.
public PrintDocument printDocument1 = new PrintDocument();
PageSettings printPageSettings = new PageSettings();
static RichTextBox printRichTextBox = new RichTextBox();
static string stringToPrint = "";
Font printFont = new Font("Arial", 10);
/****************************************************
* Select the Data->File-IO menu item. *
****************************************************/
private void fileIoToolStripMenuItem1_Click(object sender, EventArgs e)
{
File_IO fileIoDialog = new File_IO();
fileIoDialog.ShowDialog();
}
/****************************************************
* Initiate the printing process. The data to be *
* printed will be read from a file and stored in a*
* rich text box. The print menu buttons are *
* enabled. *
****************************************************/
public static void PrintInitialise(String printSource)
{
try
{
// Read text file and load into printRichTextBox.
FileStream printStream = new FileStream(printSource, FileMode.Open, FileAccess.Read);
printRichTextBox.LoadFile(printSource, RichTextBoxStreamType.PlainText);
printStream.Close();
// Initialise string to print.
stringToPrint = printRichTextBox.Text;
}
catch (Exception ex)
{
// Display error message if they appear.
MessageBox.Show(ex.Message);
}
}
/****************************************************
* Select the Data->File-IO menu item. *
****************************************************/
public void PrintDirect()
{
printDocument1.Print();
}
/****************************************************
* Select the Data->File-IO menu item. *
****************************************************/
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int numChars;
int numLines;
string stringForPage;
StringFormat strFormat = new StringFormat();
// Based on page setup, define drawable rectangle on page
}
}
}
namespace `enter code here`CSharp
{
public partial class File_IO : Form
{
MainMenu mainBransom;
public File_IO()
{
InitializeComponent();
}
private void btnPrint_Click(object sender, EventArgs e)
{
MainMenu.PrintInitialise(printSource);
mainBransom.PrintDirect();
}
두 클래스의 관련 코드를 게시하면 문제가 더 잘 이해 될 수 있습니다. – Oded
일부 코드 스 니펫을 사용하면 더 명확하게 알 수 있습니다. –