为什么在这种情况下会有额外的空间?

时间:2014-08-09 15:47:36

标签: c# .net printing arabic

这是我打印一些数据的代码:

System.Drawing.Font valueFont = new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Regular);
string dataToPrint = "";
dataToPrint += fixLength("رقم بطاقة التسويق") + farmID.Text + Environment.NewLine;
dataToPrint += fixLength("إسم صاحب المزرعة") + farmOwner.Text + Environment.NewLine;
dataToPrint += fixLength("رقم المزرعة") + farmNumber.Text + Environment.NewLine;
dataToPrint += fixLength("الموبايل") + farmMobile.Text + Environment.NewLine;
dataToPrint += fixLength("الإمارة") + emaraNameArabic.Text + Environment.NewLine;
dataToPrint += fixLength("المنطقة") + areaNameArabic.Text + Environment.NewLine;
dataToPrint += fixLength("الإقليم") + regionNameArabic.Text + Environment.NewLine;
dataToPrint += fixLength("مركز الإستلام") + receivingCenterName.Text + Environment.NewLine;
dataToPrint += fixLength("خلاص") + khalas.Text + Environment.NewLine;
dataToPrint += fixLength("فرض") + fardh.Text + Environment.NewLine;
dataToPrint += fixLength("لولو") + otherLulu.Text + Environment.NewLine;
dataToPrint += fixLength("خنيزي") + khedrawi.Text + Environment.NewLine;
dataToPrint += fixLength("بومعان") + boumaan.Text + Environment.NewLine;
dataToPrint += fixLength("برحي") + barhi.Text + Environment.NewLine;
dataToPrint += fixLength("جش خزمة") + jeshKharma.Text + Environment.NewLine;
dataToPrint += fixLength("رزيز") + reziz.Text + Environment.NewLine;
dataToPrint += fixLength("جبري") + jabri.Text + Environment.NewLine;
dataToPrint += fixLength("عنبرة المدينة") + anbaretAlMadina.Text + Environment.NewLine;
dataToPrint += fixLength("شيشي") + shishi.Text + Environment.NewLine;
dataToPrint += fixLength("دباس") + dabbas.Text + Environment.NewLine;
dataToPrint += fixLength("نبتة سيف") + nabtetSaif.Text + Environment.NewLine;
dataToPrint += fixLength("خضراوي") + khedrawi.Text + Environment.NewLine;
dataToPrint += fixLength("هلالي") + hilali.Text + Environment.NewLine;
dataToPrint += fixLength("مكتومي") + maktoumy.Text + Environment.NewLine;
dataToPrint += fixLength("نميشي") + namishi.Text + Environment.NewLine;
dataToPrint += fixLength("سلطانة") + sultanah.Text + Environment.NewLine;
dataToPrint += fixLength("بقلة الطوعة") + baqlatAlTawaa.Text + Environment.NewLine;
dataToPrint += fixLength("بقلة الدحالة") + baqlatAlDahla.Text + Environment.NewLine;
dataToPrint += fixLength("بقلة الرارنجا") + baqlatAlRarenja.Text + Environment.NewLine;
dataToPrint += fixLength("سكري") + sukary.Text + Environment.NewLine;
dataToPrint += fixLength("صقعي") + saqei.Text + Environment.NewLine;
dataToPrint += fixLength("بوزيد") + abuZebed.Text + Environment.NewLine;
dataToPrint += fixLength("مجدول") + majdoul.Text + Environment.NewLine;
dataToPrint += fixLength("شبيبي") + shabibi.Text + Environment.NewLine;
dataToPrint += fixLength("يواني") + youwani.Text + Environment.NewLine;
dataToPrint += fixLength("يردي") + yardi.Text + Environment.NewLine;
StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
e.Graphics.DrawString(dataToPrint, valueFont, System.Drawing.Brushes.Black, 600, 20, format);

这是fixLength函数:

public string fixLength(string value) {
        int difference = 40 - value.Length;
        if(difference>0)
            for (int i = 0; i < difference; i++)
            {
                value = value + " ";
            }
        return value;
    }

这是结果:  enter image description here

请注意,即使我使用了修复lenth,但打印的数据仍然没有相同的对齐方式。

1 个答案:

答案 0 :(得分:2)

我找到了自己的解决方案

        System.Drawing.Font valueFont = new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Regular);
        string dataToPrint = "";
        string valuesToPrint = "";

    dataToPrint += "رقم بطاقة التسويق" +  Environment.NewLine;
        valuesToPrint += farmID.Text + Environment.NewLine;

        dataToPrint += ("إسم صاحب المزرعة") +  Environment.NewLine;
        valuesToPrint += farmOwner.Text + Environment.NewLine;

        dataToPrint += ("رقم المزرعة") + Environment.NewLine;
        valuesToPrint += farmNumber.Text + Environment.NewLine;

        dataToPrint += ("الموبايل") + Environment.NewLine;
        valuesToPrint += farmMobile.Text + Environment.NewLine;

        dataToPrint += ("الإمارة") + Environment.NewLine;
        valuesToPrint += emaraNameArabic.Text + Environment.NewLine;

        dataToPrint += ("المنطقة") + Environment.NewLine;
        valuesToPrint += areaNameArabic.Text + Environment.NewLine;

        dataToPrint += ("الإقليم")  + Environment.NewLine;
        valuesToPrint += regionNameArabic.Text + Environment.NewLine;

    dataToPrint += ("مركز الإستلام") +  Environment.NewLine;
    valuesToPrint += receivingCenterName.Text + Environment.NewLine;

   dataToPrint += ("خلاص") + khalas.Text + Environment.NewLine;
   valuesToPrint += khalas.Text + Environment.NewLine;

    dataToPrint += ("فرض") + fardh.Text + Environment.NewLine;
    valuesToPrint += fardh.Text + Environment.NewLine;

    dataToPrint += ("لولو") + Environment.NewLine;
    valuesToPrint += otherLulu.Text + Environment.NewLine;

    dataToPrint += ("خنيزي") + khedrawi.Text + Environment.NewLine;
    valuesToPrint += khedrawi.Text + Environment.NewLine;

    dataToPrint += ("بومعان") + Environment.NewLine;
    valuesToPrint += boumaan.Text + Environment.NewLine;

    dataToPrint += ("برحي") +Environment.NewLine;
    valuesToPrint += barhi.Text + Environment.NewLine;

    dataToPrint += ("جش خزمة") +  Environment.NewLine;
    valuesToPrint += jeshKharma.Text + Environment.NewLine;

    dataToPrint += ("رزيز") + reziz.Text + Environment.NewLine;
    valuesToPrint += reziz.Text + Environment.NewLine;

    dataToPrint += ("جبري") +  Environment.NewLine;
    valuesToPrint += jabri.Text + Environment.NewLine;

    dataToPrint += ("عنبرة المدينة") +  Environment.NewLine;
    valuesToPrint += anbaretAlMadina.Text + Environment.NewLine;

    dataToPrint += ("شيشي") +  Environment.NewLine;
    valuesToPrint += shishi.Text + Environment.NewLine;

    dataToPrint += ("دباس")  + Environment.NewLine;
    valuesToPrint += dabbas.Text + Environment.NewLine;

    dataToPrint += ("نبتة سيف") +  Environment.NewLine;
    valuesToPrint += nabtetSaif.Text + Environment.NewLine;

    dataToPrint += ("خضراوي") + Environment.NewLine;
    valuesToPrint += khedrawi.Text + Environment.NewLine;

    dataToPrint += ("هلالي") +  Environment.NewLine;
    valuesToPrint += hilali.Text + Environment.NewLine;

    dataToPrint += ("مكتومي") +  Environment.NewLine;
    valuesToPrint += maktoumy.Text + Environment.NewLine;

    dataToPrint += ("نميشي") +  Environment.NewLine;
    valuesToPrint += namishi.Text + Environment.NewLine;

    dataToPrint += ("سلطانة") +  Environment.NewLine;
    valuesToPrint += sultanah.Text + Environment.NewLine;

    dataToPrint += ("بقلة الطوعة")  + Environment.NewLine;
    valuesToPrint += baqlatAlTawaa.Text + Environment.NewLine;

    dataToPrint += ("بقلة الدحالة") +  Environment.NewLine;
    valuesToPrint += baqlatAlDahla.Text + Environment.NewLine;

    dataToPrint += ("بقلة الرارنجا") +  Environment.NewLine;
    valuesToPrint += baqlatAlRarenja.Text + Environment.NewLine;

    dataToPrint += ("سكري") + Environment.NewLine;
    valuesToPrint += sukary.Text + Environment.NewLine;

    dataToPrint += ("صقعي") + Environment.NewLine;
    valuesToPrint += saqei.Text + Environment.NewLine;

    dataToPrint += ("بوزيد") + Environment.NewLine;
    valuesToPrint += abuZebed.Text + Environment.NewLine;

    dataToPrint += ("مجدول") + Environment.NewLine;
    valuesToPrint += majdoul.Text + Environment.NewLine;

    dataToPrint += ("شبيبي") +  Environment.NewLine;
    valuesToPrint += shabibi.Text + Environment.NewLine;

    dataToPrint += ("يواني") +  Environment.NewLine;
    valuesToPrint += youwani.Text + Environment.NewLine;

    dataToPrint += ("يردي") + Environment.NewLine;
    valuesToPrint += yardi.Text + Environment.NewLine;

    dataToPrint += ("خدي") + Environment.NewLine;
    valuesToPrint += khadi.Text + Environment.NewLine;

    dataToPrint += ("حاتمي") +  Environment.NewLine;
    valuesToPrint += hatimi.Text + Environment.NewLine;

    dataToPrint += ("نغال") +  Environment.NewLine;
    valuesToPrint += neghal.Text + Environment.NewLine;

    dataToPrint += ("مجموعة مساير") + Environment.NewLine;
    valuesToPrint += otherSayer.Text + Environment.NewLine;

    dataToPrint += ("إجمالي مثمر") +  Environment.NewLine;
    valuesToPrint += totalFructiferous.Text + Environment.NewLine;

    dataToPrint += ("إجمالي غير مثمر") + Environment.NewLine;
    valuesToPrint += totalUnFructiferous.Text + Environment.NewLine;

    dataToPrint += ("إجمالي الأفحل") +  Environment.NewLine;
    valuesToPrint += totalAfhal.Text + Environment.NewLine;

    dataToPrint += ("الإجمالي العام") +  Environment.NewLine;
    valuesToPrint += generalTotal.Text + Environment.NewLine;

    dataToPrint += ("كبير المعرفين") +  Environment.NewLine;
    valuesToPrint += seniorSupervisors.Text + Environment.NewLine;

    dataToPrint += ("مساعد") +  Environment.NewLine;
    valuesToPrint += assistant.Text + Environment.NewLine;

    dataToPrint += ("مدخل البيانات")+  Environment.NewLine;
    valuesToPrint += dataEntry.Text + Environment.NewLine;

    dataToPrint += ("صاحب المزرعة أو من ينوب عنه") +  Environment.NewLine;
    valuesToPrint += farmOnwerOrBehalf.Text + Environment.NewLine;

    StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
        e.Graphics.DrawString(dataToPrint, valueFont, System.Drawing.Brushes.Black, 600, 20, format);
        e.Graphics.DrawString(valuesToPrint, valueFont, System.Drawing.Brushes.Red, 400, 20, format);

这是结果

enter image description here